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.

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 AM EDT
As much as I'd love to sit here and gloat, the truth is that I read your
question and though "wait, I know Tim doesn't do that when skinning our
applications." Since he's 15 feet away, I just asked him, and he replied that
he simply never needed to use any path information when the image resource was
local. But I couldn't have told you with a gun to my head whether that was
because Xpages, Domino or the CSS spec had a rule about how relative paths
worked.

One potentially useful thing I can tell you is that Xpages has some automatic
translation of paths for anything coming from Dojo. And if you drop later
versions of Dojo into a sibling path to the default dojo1.3.2 folder on your
server, it will use those instead. That's how we were able to include some
1.4.1 stuff in recent projects.

Anyway, I'm glad to have introduced anything that will save you work. Sorry
we didn't have this conversation 5 years ago. :-)
re: File this under "Damn, I should have known that" -- CSS and Relative PathsBy Charles Robinson on 03/18/2010 at 10:02 AM EDT
When I played around with Domino web apps a few years ago (6.x) I stumbled
across this functionality. I read the CSS spec and just assumed everyone else
already knew about it, and I didn't because I was a newbie. :-)
re: File this under "Damn, I should have known that" -- CSS and Relative PathsBy Bruce Lill on 03/18/2010 at 11:30 AM EDT
It's relative to the last "/" which may or may not be the filename. If you set
an xpage to the launched at start-up it will point to the path not the nsf >>
web/home.nsf has h.xsp as start-up page will have a relative path of web/ but
web/home.nsf/h.xsp will work.

I see this when developers also put the css in the HTML of the form/page
instead of as a CSS file.

Always test in a sub-folder.
re: File this under "Damn, I should have known that" -- CSS and Relative PathsBy Andrew Pollack on 03/18/2010 at 11:49 AM EDT
that depends. If the xpage calls out to an external css file, then it's the
last / (the realm) that the CSS file resides in, not the xpage -- at that
point, the xpage's location has no relationship to the relative path of the
objects referenced in the external css file.


Other Recent Stories...

  1. 03/26/2019Undestanding how OAUTH scopes will bring the concept of APPS to your Domino serverWhile a full description of OATH is way beyond what I can do in this quick blog entry, I wanted to talk a bit about how "SCOPES" interact with the already rich authorization model used by Domino. Thanks to the fantastic work by John Curtis and his team, the node.js integration with Domino is going to be getting a rich security model. What we know is that a user's authorizations will be respected through the node.js application to the Domino server -- including reader names, ACLs, Roles, and so on. The way ...... 
  2. 02/05/2019Toro Yard Equipment - Not really a premium brand as far as I am concernedDear Toro Customer Service, I arm writing about the following machine: Toro Power Max 1120 OXEModel:38654S/N:31000#### Specifically, bearing part #:63-3450 This is the part ($15 online / $25 at the local dealer) that caused me to raise my objections on-line. This piece of garbage is supposed to be a bearing. It carries the shaft which drives both stages of the auger. The shaft passes through the bearing (which is what bearings do) after the auger drive pulley as the shaft goes through the back (engine ...... 
  3. 10/08/2018Will you be at the NYC Launch Event for HCL Domino v10 -- Find me!Come find me in NYC on Wednesday at the Launch Event if you're there. I really do want to talk to ...... 
  4. 09/04/2018With two big projects on hold, I suddenly find myself very available for new short and long term projects.  
  5. 07/13/2018Who is HCL and why is it a good thing that they are now the ones behind Notes and Domino? 
  6. 03/21/2018Domino Apps on IOS is a Game Changer. Quit holding back. 
  7. 02/15/2018Andrew’s Proposed Gun Laws 
  8. 05/05/2016Is the growing social-sourced economy the modern back door into socialism? 
  9. 04/20/2016Want to be whitelisted? Here are some sensible rules for web site advertising 
  10. 12/30/2015Fantastic new series on Syfy called “The Expanse” – for people who love traditional science fiction 
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.