Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache busting does not work when using absolute path on the serve from parameter #172

Open
sashee opened this issue May 15, 2014 · 3 comments

Comments

@sashee
Copy link

sashee commented May 15, 2014

I have an app that uses absolute path (it loads some static files (css/js/fonts) from a gem) and noticed that cache busting is not working this way. The serving and the concatenation is working fine, but I'm getting just app.js and not app.hash.js (and also for the css).

I've traced back to: https://github.com/rstacruz/sinatra-assetpack/blob/master/lib/sinatra/assetpack/options.rb#L264 . Here the absolute path (local_path) is joined to the app root, effectively making /home/user/... to /home/user/.../home/user/... .

I ended up using Pathname.new(path).relative_path_from(Pathname.new(app.root)).to_s to relativize the absolute path from the root, but I think it should work this way.

@jsignanini
Copy link

Could you please further explain how you managed to get around this issue?

@sashee
Copy link
Author

sashee commented Aug 4, 2014

I have a gem that has some assets which I want to include in the app.js and app.css. I find the assets using:

Gem::Specification.find_by_name(gemname).gem_dir+'/assets/javascripts'

It gives me an absolute url, like:

 /home/sashee/.rvm/gems/.../assets/javascripts

Using this absolute url like this:

serve '/js',       from: abs_url

does not work.

The workaround is to relativize it to app.root:
This:

Pathname.new(abs_url).relative_path_from(Pathname.new(app.root)).to_s

makes the abs_url to like this:

../../../.rvm/gems/.../assets/javascripts

And using this url on the serve works fine.

@cernyjakub
Copy link

I have come into the same problem, your proposed solution works for me. Thanks!

Will try to make a patch later on...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants