magnars / optimus

A Ring middleware for frontend performance optimization.
364 stars 23 forks source link

paths starting with / #22

Closed humanitiesNerd closed 9 years ago

humanitiesNerd commented 10 years ago

why must paths start with a slash ?

magnars commented 10 years ago

Which paths where?

humanitiesNerd commented 10 years ago

Sorry for being unclear.

I'm experimenting with Optimus and Stasis.

I have a couple of pages and they are working on my local web server.

Not so on github pages, because the resources managed through Optimus have paths as "/stylesheets/style.css" or "/img/background.jpg"

Because on github pages the URL is like

https://blah/blah/index.html

resources are not reached as they are not at https://blah/stylesheets/style.css and https://blah/img/background.jpg but rather at https://blah/blah/stylesheets... etc

I tried to change the paths to

"stylesheest/style.css" and "img/background.jpg"

that is, without the starting slash, that is with relative paths

but an exception gets thrown. I explored the code and there's a "guard-path" function that does exactly this: it checks that paths start with a slash, if they don't it throws an exception.

Enforcing the slash in the beginning cuts out the use case where your site has not its own domain name.

I was wondering what's the reasoning behind this.

My aim is to create a blog made with static files and have it hosted on simple free setups.

That's all

magnars commented 10 years ago

Hi! Thanks for elaborating. I'll give it some thought, but have you looked at Optimus' :base-dir option? Sounds like it could solve your issue.

Den 3. mai 2014 kl. 12:16 skrev humanitiesNerd notifications@github.com:

Sorry for being unclear.

I'm experimenting with Optimus and Stasis.

I have a couple of pages and they are working on my local web server.

Not so on github pages, because the resources managed through Optimus have paths as "/stylesheets/style.css" or "/img/background.jpg"

Because on github pages the URL is like

https://blah/blah/index.html

resources are not reached as they are not at https://blah/stylesheets/style.css and https://blah/img/background.jpg but rather at https://blah/blah/stylesheets... etc

I tried to change the paths to

"stylesheest/style.css" and "img/background.jpg"

that is, without the starting slash, that is with relative paths

but an exception gets thrown. I explored the code and there's a "guard-path" function that does exactly this: it checks that paths start with a slash, if they don't it throws an exception.

Enforcing the slash in the beginning cuts out the use case where your site has not its own domain name.

I was wondering what's the reasoning behind this.

My aim is to create a blog made with static files and have it hosted on simple free setups.

That's all

— Reply to this email directly or view it on GitHub.

humanitiesNerd commented 10 years ago

Magnars,

it worked. Thanks

But I'd still be interested in knowing your reasons for absolute paths.

magnars commented 10 years ago

Good to hear. Some reasons:

The absolute paths are unique identifiers for assets and pages, that are used to look up what to serve when a request comes in. Those requests come with absolute URLs.

Absolute paths are simpler than relative paths, in the non-complex sense. This makes the code easier to reason about - by quite a bit, since both the parent and child assets may change their place in the directory tree as part of transformations.

It is certainly possible to add an asset transformation middleware that could be added to the very end, that rewrites all references to relative, tho.

On Sun, May 4, 2014 at 11:09 AM, humanitiesNerd notifications@github.comwrote:

Magnars,

it worked. Thanks

But I'd still be interested in knowing your reasons for absolute paths.

— Reply to this email directly or view it on GitHubhttps://github.com/magnars/optimus/issues/22#issuecomment-42128200 .