documentcloud / jammit

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

embed_assets: on has no effect #153

Closed fwoeck closed 13 years ago

fwoeck commented 13 years ago

Hi, we're using rails304, jammit 0.6.0 with yui-compressor 0.9.1 (for the 2.4.2 version of the compressor). Compression in gerneral works, but I won't get the images embedded, like this:

.icon.ws_sidebar.new_msg { background-image: url(../images/embed/ws_sidebar_new_msg_unselected.png?1301051849); }

The result simply stays like this. Could it relate to sass (via compass) that we use, or the timestamps? Best regards -- Frank

jashkenas commented 13 years ago

I bet it's the timestamp ... which doesn't make much sense to have in your CSS ... but it could also be that the image is over the 32K limit.

fwoeck commented 13 years ago

Hi, thank your for the quick reply! Ok, I had to be more precise - the scss-sourcecode looks like this:

.icon.ws_sidebar.new_msg { background-image: url(../../images/embed/ws_sidebar_new_msg_unselected.png); }

and the timestamp ist magically added by compass/sass. I had a glance at the sass options, but it's at least not trivial to me to disable this. --Frank

jashkenas commented 13 years ago

Alright ... I'll see if we can enhance the asset-matching regex to ignore query strings after the file extension.

fwoeck commented 13 years ago

PS. but I understand that there's probably no obvios mistake in it - so I'll try to kill the timestamps first

fwoeck commented 13 years ago

"enhance the asset-matching regex to ignore query strings " Would be great :)

fwoeck commented 13 years ago

Now I used ENV['RAILS_ASSET_ID'] = "" in an initializer and the timestamps went away (sass compiled result):

/* line 554, ../../../app/stylesheets/partials/_workspace.scss */ .icon.ws_sidebar.new_msg { background-image: url(../images/embed/ws_sidebar_new_msg_unselected.png); }

but the images aren't embedded either. Is it possible, that the path (that is relative to public/stylesheets/compiled for compass) is the problem? I tried to fiddle around with the relative path localtion without success. --Frank

heikki commented 13 years ago

http://compass-style.org/docs/tutorials/configuration-reference/ asset_cache_buster :none

fwoeck commented 13 years ago

Hi heikki, thanks for the hint - the asset_cache_buster in my case doesn't prevent the timestamps from beeing generated. Setting ENV['RAILS_ASSET_ID'] = "" did remove them, but the images weren't embedded either. --Frank

jashkenas commented 13 years ago

In that case, the problem lies elsewhere. You can debug it by dropping some logging in here:

https://github.com/documentcloud/jammit/blob/master/lib/jammit/compressor.rb#L152-158

But perhaps the question is more obvious. Jammit doesn't embed assets in development ... are we talking about development here?

fwoeck commented 13 years ago

Tried it in dev-mode and production too. I'll try to watch the with_data_uris(css) you pointed out and see what I find! --Frank

fwoeck commented 13 years ago

What I got out this far is, that @variant in line 72 of controller.rb becomes nil.

When I set it to :datauri, things work. The closer reason is, that params[:package] equals to 'common'. I didn't track it further down until now. The params I use are:

package_path: packages embed_assets: datauri package_assets: on compress_assets: off javascript_compressor: yui

--Frank

fwoeck commented 13 years ago

Arrghh, I found out, that you get the embedded version, when you address your stylesheet named "common" via "common-datauri.css" :)

Wouldn't hurt to point this out at a prominent place. If I just missed it, I apologize. Thank you for your work and support! --Frank

jashkenas commented 13 years ago

Hey Frank.

I'm afraid that unless you use the Jammit helper for include_stylesheets -- you aren't going to be serving the right stylesheets to the right browsers, without a lot of special care / conditional-comments. Just use the Jammit helpers, and all the right assets should be served.

fwoeck commented 13 years ago

Ah I see, the helpers do the browser detection and so on. Thank you! --Frank