documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.io/jammit/
MIT License
1.16k stars 197 forks source link

Production - No Cache busting timestamp on js and css packaged files #208

Closed bokor closed 12 years ago

bokor commented 13 years ago

I'm using the following Rails 3.0.9 Jammit 0.6.2 Jammit-s3 :branch aws-s3 Engine yard deployment

I can't seem to figure out why my s3 urls won't add the ?<%mtime%> to the end of the url for js and css packaged assets. It appears to work in development but not in production. All my other assets add the cache busting url param but just not the jammit created ones. Is there something I might need to add to the config or add to my environment for force this? Anyone that can help, please help! I'm stuck here. Thank you so much!

bokor commented 13 years ago

Ok I have tested more and I went back to version 0.6.1 and it works again....so not sure what changed but it doesn't constantly put the cache busting timestamp. Will have to try to review the code tomorrow or wednesday to see if I can fix the issue

tute commented 12 years ago

I'm having the same issue on Rails 3.1.3. Didn't work with versions 0.6.1, 0.6.3 nor 0.6.5.

jashkenas commented 12 years ago

For what it's worth, we're on Rails' 2.3 series, and the cache busting timestamps are working fine.

tute commented 12 years ago

I see that include_javascripts is calling Jammit.asset_url(pack, :js), but asset_url(package, extension, suffix=nil, mtime=nil) doesn't add the timestamp if mtime is nil...

tute commented 12 years ago

This patch solves it for me:

From 12c3f3f71461f1c597fb87bb5866e765a6e18323 Mon Sep 17 00:00:00 2001
From: Tute Costa <tutecosta@gmail.com>
Date: Fri, 30 Dec 2011 14:12:49 -0300
Subject: [PATCH] Adding timestamp to include_javascripts.

---
 lib/jammit/helper.rb |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/jammit/helper.rb b/lib/jammit/helper.rb
index 530bc1b..6cdf088 100644
--- a/lib/jammit/helper.rb
+++ b/lib/jammit/helper.rb
@@ -27,7 +27,7 @@ module Jammit
     def include_javascripts(*packages)
       options = packages.extract_options!
       html_safe packages.map {|pack|
-        should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js)
+        should_package? ? Jammit.asset_url(pack, :js, nil, Time.now) : Jammit.packager.individual_urls(pack.to_sym, :js)
       }.flatten.map {|pack|
         javascript_include_tag pack, options
       }.join("\n")
-- 
1.7.7.1
jashkenas commented 12 years ago

Want to open a pull request for your patch?

tute commented 12 years ago

Just did it, it's in https://github.com/documentcloud/jammit/pull/214. Thanks!

jashkenas commented 12 years ago

Took a closer look, and closed the pull request because I don't think that it's correct.

The timestamp functionality within asset_url is purely for generating correct absolute URLs for MHTML generation. In Rails, Rails itself should already be adding the cachebuster for you. If it's not ... then there's something wrong with your Rails setup.

Are you generating the packaged assets in advance, so that they're written out to public?

tute commented 12 years ago

Thank you @jashkenas. Yes, I am packaging them in advance and they are referenced from public. I'll continue chasing this issue then.

tute commented 12 years ago

Holy... ENV["RAILS_ASSET_ID"] = ""! Thanks and sorry to bother.

jashkenas commented 12 years ago

Oh man. That's pretty funny.

tute commented 12 years ago

More: asset pipeline has to be disabled for this to happen (but I need it for a gem to run, just 2 more cents).

bokor commented 12 years ago

I have found that If i run jammit on my utility server it will not work with the timestamp but does on my application server.

blim8183 commented 12 years ago

Packaging the files in advance worked for me too when I had this issue but this is a less than ideal solution for me since I'm actually serving these files from a separate S3 server. Is there a way to ensure that the timestamps are appended without having to generate the files and upload them on to my application servers?