Forgive my naivety but I’m a little unclear as to the benefit Base Href provides over simply using URLs from the root of the domain. i.e. "/css/styles.css" rather than "css/styles.css"?
I understand that the latter in that example would create problems on 404 pages, but it would work without issue with the prepended "/". From what I can see prepending links with "/" maintains portability and allows for the use of anchors (without hacks).
Certainly not if you develop or deploy in a subdirectory. Absolute paths ruin portability.
I’ve started using a property on my Templates for referencing things like CSS and JS files, template_url, giving it a value like:
Granted in CSS and Javascript this is still an issue, but that’s why my CSS and JS are static resources and use [[~...]] tags in them
[[++assets_url]]templates/mytemplatename/
<link href="[[+template_url]]css/960.css" rel="stylesheet" type="text/css" /> <link href="[[+template_url]]style.css" rel="stylesheet" type="text/css" /> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script> <![endif]--> <!--[if lte IE 7]> <link href="[[+template_url]]css/ie.css" rel="stylesheet" type="text/css" /> <![endif]-->
I prefer this approach simply because using Static Resources for JS and CSS can incur more overhead than allowing browsers to properly cache them. In addition, I can easily switch the location of those files by altering the property value, say, if I wanted to redeploy the JS and CSS to a CDN.
body { background-image: url('[[~24? &scheme=`full`]]'); }
using Static Resources for JS and CSS can incur more overhead than allowing browsers to properly cache them
Neither do I; I use the base href.
I don’t ever have to worry about file paths or file renames breaking the site - as long as the IDs remain the same. If I didn’t have that stylesheet as a static resource, I wouldn’t be able to do this.
You invoke PHP. That is automatically more overhead than serving any static file with the web server directly, and always will be. And there is no way for the web server to report if the CSS file has changed, so yes, it gets invoked on every request. Static files would actually be cached on the client.
Quote from: OpenGeek at Nov 26, 2010, 08:12 PM
using Static Resources for JS and CSS can incur more overhead than allowing browsers to properly cache them
Just out of interest, how does a static resource serving up a CSS file differ from serving up the CSS file directly. As long as the resource is set as cacheable in modx, and I don’t play with the caching headers in the output, surely the browser will treat the output as any other CSS file - it doesn’t know that it’s dynamically created in modx and not to cache it unless I tell it so (i.e. HTTP headers?)