Permalink
Browse files

Provide a way to access to assets without using the digest, useful fo…

…r static files and emails
  • Loading branch information...
1 parent 1187011 commit 82afaa06861d03f6a2887d40e40c0ded76db88db @spastorino spastorino committed Sep 13, 2011
Showing with 6 additions and 0 deletions.
  1. +1 −0 actionpack/lib/sprockets/assets.rake
  2. +3 −0 railties/CHANGELOG
  3. +2 −0 railties/test/application/assets_test.rb
@@ -43,6 +43,7 @@ namespace :assets do
mkdir_p filename.dirname
asset.write_to(filename)
asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
+ asset.write_to(target.join(logical_path))
end
end
end
View
@@ -12,6 +12,9 @@
*Rails 3.1.0 (unreleased)*
+* Provide a way to access to assets without using the digest, useful for
+static files and emails. [Santiago Pastorino]
+
* The default database schema file is written as UTF-8. [Aaron Patterson]
* Generated apps with --dev or --edge flags depend on git versions of
@@ -58,7 +58,9 @@ def app
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
end
files = Dir["#{app_path}/public/assets/application-*.js"]
+ files << Dir["#{app_path}/public/assets/application.js"].first
files << Dir["#{app_path}/public/assets/foo/application-*.js"].first
+ files << Dir["#{app_path}/public/assets/foo/application.js"].first
files.each do |file|
assert_not_nil file, "Expected application.js asset to be generated, but none found"
assert_equal "alert()", File.read(file)

13 comments on commit 82afaa0

Contributor

dmathieu replied Sep 14, 2011

This would be nice to deactivate. We might not all want to keep public access to our uncompressed javascripts.

Contributor

ay replied Sep 14, 2011

I agree with @dmathieu. Why is this needed for emails?

Member

sikachu replied Sep 14, 2011

Contributor

dmathieu replied Sep 14, 2011

Won't this problem be solved with the use of exceptron in 3.2 ?

Contributor

ay replied Sep 14, 2011

@sikachu Ah, that makes sense. Personally, I would probably embed any JS/CSS in the static .html file directly so a way to turn this off would be nice. Perhaps config.assets.precompile_digests_only = true?

Owner

guilleiguaran replied Sep 14, 2011

I agree, this would be nice to deactivate since no all the users want have their assets duplicated.

Owner

guilleiguaran replied Sep 14, 2011

btw, I'm sure this isn't working as expected, the undigested assets will have references to digested files.

Owner

spastorino replied Sep 14, 2011

No worries guys this is going to be reverted, public dir is still there to place assets so is probable the best thing for static + emails stuff.

Member

sikachu replied Sep 14, 2011

Yeah, I agree that this should be reverted. I didn't like this solution.

I'm disagree on using public/ to serve static/e-mail stuff, as I would still suffer from having to maintain multiple copies of my js/css files. I've proposed a middleware solution which will lookup your /assets/* in your manifest file and send 302 redirect to the correct file.

Why not 301 you ask? Because browser might still caching 301 redirect and may redirect user to the outdated version of the assets (with old digest in the file name.)

I think that is the solution to this problem in case you want to access the file without the digest. That would also fixing the concern that @dmathieu has about letting someone accessing uncompressed javascript (as they would get redirected to the digested, compressed file.

I will make this middleware as a gem first, and if Rails team like it it can be included - but turned off by default - into Rails.

Contributor

dmathieu replied Sep 14, 2011

I like this middleware idea. Thanks @sikachu.

Member

josevalim replied Sep 14, 2011

In case this is not going to be reverted, I believe the option to deactivate should actually be a regexp that allows you to filter what to copy (so you can copy just images for example)

Contributor

maximeg replied Oct 6, 2011

Just a note to say that some doesn't want a real copy of the assets without digest.

I use a symbolic link for the files i need without digest.
Unless, it is such a waste of space.

Owner

guilleiguaran replied Oct 6, 2011

@maximeg, to get only digested version of assets:

bundle exec rake assets:precompile:primary RAILS_ENV=production RAILS_GROUPS=assets

I will add this one as shorthand in Rails 3.1.2:

bundle exec rake assets:precompile:digest

Please sign in to comment.