Andrew Pollack's Blog

Technology, Family, Entertainment, Politics, and Random Noise

File this under "Damn, I should have known that" -- CSS and Relative Paths

By Andrew Pollack on 03/18/2010 at 07:33 AM EDT

I was whining about a feature being missing in Designer 8.5.x yesterday in a closed forum for "Design Partners" when I learned something I wished I'd known a long time ago. I'm writing this to share it with you, so you can be saved the work I've been doing.

The feature I wanted (and still want) is for file resources that use the new editors (e.g. CSS, HTML, JAVASCRIPT) to allow "<computed text>" values or at least some form of tokenization to allow you to include things like "@webdbname" and profile document values in your CSS or Javascript files Without such a feature I've had to create "page" elements instead without the snazzy editors.

I was describing the problem in context of CSS pages and paths to image resources stored in the same database, when Nathan made a comment that it just seems to work fine for him. So, of course first I declared that I was more than 99% sure that was impossible, but then (giving the man his due) I decided to research it. Of course, I learned something I should have known.

If you look at the CSS Spec ( http://www.w3.org/TR/REC-CSS1/ ) section 6.4 clearly states

Partial URLs are interpreted relative to the source of the style sheet, not relative to the document:.
.
So, what that means in a Domino database is that if you have a file resource, it is always accessed relative to the top of the NSF (e.g. ../../mydatabase.nsf/myImage.jpg ) and your CSS file is the same (e.g. ../../mydatabase.nsf/mystyle.css ). Even if the document you're loading the css from is in a different database, or in a view or document buried down somewhere inside that database, as long as the images referenced in the css URL() statements are in the same database as the CSS file itself, they'll be seen and loaded correctly without having to specify the full path to the images.

In other words, if you have mystyle.css as a file resource in mydatabase.nsf, and it contains this statement:

div.myFancyDiv { background-image:url(mybackground.jpg) ; }

It will work even if you are calling to /mydatabase.nsf/mystyle.css from another database, another server, a view nested deeper in the same database, or anywhere else.

When I think of how many wasted hours I've spent.....ugh.

  • car icon

    Server Performance

    Are your servers underperforming? Just buying new boxes isn't the answer. If you want to get better performance from your existing servers, Contact Me.
  • There are  - loading -  comments....

    re: File this under "Damn, I should have known that" -- CSS and Relative PathsBy Nathan T. Freeman on 03/18/2010 at 08:25 EDT
    Comment Loading
    re: File this under "Damn, I should have known that" -- CSS and Relative PathsBy Charles Robinson on 03/18/2010 at 10:02 EDT
    Comment Loading
    re: File this under "Damn, I should have known that" -- CSS and Relative PathsBy Bruce Lill on 03/18/2010 at 11:30 EDT
    Comment Loading
    re: File this under "Damn, I should have known that" -- CSS and Relative PathsBy Andrew Pollack on 03/18/2010 at 11:49 EDT
    Comment Loading


    Other Recent Stories...

    1. 07/20/2010IBM has invented the time machine - and not in a good waySteve Mills is now in charge of both hardware and software. According to The New York Times.... The management changes, announced in an e-mail message to I.B.M. employees, were intended to improve the company’s products and services, Mr. Palmisano wrote. For example, computer hardware and software are for the first time being placed under the oversight of one executive......Increasingly, Mr. Palmisano wrote, computer systems must be “designed and brought to market as tightly integrated” packages of ...... 
    2. 07/18/2010A lot of work, but something I've always wanted to do -- Fixing up a car for one of my kidsOne of the things I've thought about for years and have always wanted to do, is to fix up a car for one of my kids. I'm not sure why, but its just something that I've thought about since they were really small. Of course, daydreams being what they are, the reality is never quite as grand in scale -- the 70's era muscle car turns out to be a 2002 Kia, and instead of an old pole barn to work in, the car is up on ramps in my driveway. Still, I'm really enjoying getting to do the work, being able to do the ...... 
    3. 07/13/2010Old Spice -- Their marketing team fully groks social media. You know the old spice guy (I'm on a boat)? I don't care for their products, but their ad people have gone social nuclear. Read this to see how they've totally "Got" social media promotion. ...... 
    4. 06/22/2010Product Review: Plantronics Savi Office wireless headset 
    5. 06/16/2010Ed Brill has a blog. Peter O'Kelly has blog... 
    6. 06/15/2010How about Traveler for Desktop? 
    7. 06/15/2010Why XPages is not LCD any more 
    8. 06/15/2010Fixing Domino Designer -  
    9. 06/14/2010Bandwagon: Why the decline in Notes seats, when the Domino server is still the best value on the marketplace? Here's why.... 
    10. 05/17/2010Unified Comunications Server? That ship sailed -- it's time to move on. 
    Click here for more articles.....


    pen icon Comment Entry
    Subject
    Your Name
    Homepage
    *Your Email
    * Your email address is required, but not displayed.
     
    Your thoughts....
     
    Remember Me  

    Please wait while your document is saved.