Question

This should be a quick quesiton but I cannot google the answer because it just tells me to edit my .htaccess file. I have .htaccess enabled, I copied the HTML5 boiler plate for it as well as removed that and added http://www.feedthebot.com/pagespeed/enable-compression.html this one in it's place.

Gzip is still not enabled, I have a Gulp.js plugin that gzips things so my question is, do I send users a file.js.gz? or file.js? file.js doesn't seem to be compressed and file.js.gz isn't decompressing which is breaking the site.

I created a php info page, according to that the Apache environment has mod_deflate enabled.

Was it helpful?

Solution

If you use Apache server to serve the HTTP requests, with mod_deflate enabled and configured, the requests for a file.js will be served a gzip-ed version of it, with a response header telling the user agent that the output is gzip-ed (here, I'm assuming that you enabled gzip compression for *.js files). Therefore, you do not need to change the file extensions of your files.

I'm not sure how you use Gulp.js in your setup since it is a Node.js component and you are asking about Apache configuration.

Also to point out:

Some popular browsers cannot handle compression of all content (http://httpd.apache.org/docs/2.2/mod/mod_deflate.html)

OTHER TIPS

Once you have mod_deflate enabled, the server does the compression. In your htaccess, you can specify the file types to compress. Just server the js file as normal and don't change the extension, the server will do the rest once you've added the parameters.

Like this

AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Or here is an example that will match by file extension. Customize as you needed.

<FilesMatch "\\.(js|css|html|htm|php|xml)$">

SetOutputFilter DEFLATE

</FilesMatch>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top