ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Relative path vs. Absolute path and the {site_url} global

July 07, 2012 11:21am

Subscribe [2]
  • #1 / Jul 07, 2012 11:21am

    mlangford

    7 posts

    I’m fairly new to EE development, but I’ve noticed that the convention seems to be to use the {site_url} value on all links.  This results in those links being rendered out as absolute urls, which over the last decade and a half I’ve been doing this sort of thing has always been a no-no for a variety of reasons (mostly performance-related since it requires an extra round-trip from the DNS server).  Pretty much no major CMS that I’ve worked with over the years (Drupal, Wordpress, Joomla, TeamSite, Vignette, DotNetNuke…) used absolute links as convention, but yet EE does—why?

    The reason I personally don’t like it is that it makes local development really hard when, for example, I’m offline.  If all my links, all my assets, all my images, all my CSS, etc, are all using absolute links and I’m, say, on a plane (that doesn’t have reliable wifi) or otherwise somewhere that I can’t get online, I can’t do any work because the CSS, scripts, assets, links, etc, all will end up being broken unless I modify my host file to force the Stage URL to be my Local url—which is a really hamfisted way to have to do it.

    The easy answer is—don’t like the convention?  don’t do it.  I get that…  but my question isn’t what do I do about it (I already know what I can do about it).  My question is WHY is this the convention?  What is the rationale Ellis Labs (or the community as a whole) uses to justify this—other than that, well, the {site_url} global variable is there, so lets just use it everywhere, yahey!

    (Note, I asked Boyink when he came to do a class at my company some weeks ago, and *I believe* he said something about making the site more portable because you can change the URL in the configuration—that answer doesn’t work for me for the obvious reason that NOT using the site_url value for everything means it’s domain agnostic and therefore fully portable without needed any configuration changes at all.  At the very least, this is extra bytes on the page that are unnecessary…)

    Thanks!

  • #2 / Jul 09, 2012 11:29am

    Shane Eckert

    7174 posts

    Hey Kvetchus,

    Thank you for posting your question here on the ExpressionEngine forums.

    You question is why do we offer {site_url} which is an absolute path? Because we can! We want to provide our users with many options. {site_url} is just one of the many ways that ExpressionEngine is flexible.

    A few suggestions that might help with relative and absolute paths.

    1. Master Config is great for managing multiple environments.

    2. Greeny is a useful tool for managing absolute and relative paths.

    3. You have the option of not touching {site_url} and sticking with paths.

    Lastly, a quick change to the hosts file will allow you to continue use of absolute paths offline.

    I hope this helps!

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases