-
Notifications
You must be signed in to change notification settings - Fork 791
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
Skip GZip generation depend on specific file parameters #221
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Does generating the gzip for this example cause any issue? Or does it just an optimization to avoid unnecessary work? |
Browsers can't open this gzip image. and if we have them in our assets directory, apache/nginx/CDN will serve them instead of normal image. |
Sprockets shouldn't be compressing a PNG it explicitly checks a field in the mine type to see if it is text data before zipping. I'm on mobile right now but I even put a comment on the line that does the check. So a good question would be how did that mime type get modified in your example? Can you give me a minimal example app that reproduces the problem? |
I have created new rails application to show this actually in new application add in file (config/initializers/assets.rb)
then after (before add some png files to assets/images) output:
probably you are refering to this comment in method can_compress?(mime_types)
there is no charset for images, because it doesn't have any preprocessor (loader.rb), but when we add some it will add charset as ascii-8bit |
Here's the problem line: sprockets/lib/sprockets/loader.rb Line 164 in 65504dd
The charset is assigned automatically based on the source encoding in the text that was read from the file which in this case is ascii-8bit. This is incorrect. Unfortunately due to the direction of the merge you can't manually tell it to do the right thing by specifying a |
If a charset is returned by a pre-processor use it instead of automatically assigning one. This is needed so that non-gzippable assets will not accidentally be assigned a charset and gzipped later. We're also removing a hash allocation needed for `Hash.merge!`.
Here's my proposed solution. Need to add tests for this new behavior but it looks like it won't break anything which is good. |
Link: #224 |
Can you comment on #224? |
[close #221] Favor charset from processor
If a charset is returned by a pre-processor use it instead of automatically assigning one. This is needed so that non-gzippable assets will not accidentally be assigned a charset and gzipped later. We're also removing a hash allocation needed for `Hash.merge!`.
If a charset is returned by a pre-processor use it instead of automatically assigning one. This is needed so that non-gzippable assets will not accidentally be assigned a charset and gzipped later. We're also removing a hash allocation needed for `Hash.merge!`.
If a charset is returned by a pre-processor use it instead of automatically assigning one. This is needed so that non-gzippable assets will not accidentally be assigned a charset and gzipped later. We're also removing a hash allocation needed for `Hash.merge!`.
Allow to skip generation gzip file for specific file
If you specific preprocessor for images
then sprocket generate gzip file for image which doesn't make sence because png file was already optimized
when we add skip_gzip: true in the processor return and sproket will skip gzip generation