I've compressed JavaScript and CSS files using gzip
. The JS files are already minified before it compressed with gzip cmd.
Now I need to tell apache to serve gzipped version of those files, if the browsers are compatible. For that I've added few lines of code in htaccess like this:
AddType "text/javascript" .gz
AddType "text/css" .gz
AddEncoding gzip .gz
RewriteCond %{REQUEST_FILENAME} \.(js|css)$
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ /$1.gz [QSA,L]
<FilesMatch .*\.js.gz$>
ForceType text/javascript
Header set Content-Encoding: gzip
</FilesMatch>
<FilesMatch .*\.css.gz$>
ForceType text/css
Header set Content-Encoding: gzip
</FilesMatch>
And the directory structure for the files inside public_html as follows:
css/style.css
css/style.css.gz
js/customjsfn.min.js
js/customjsfn.min.js.gz
js/jquery.js
js/jquery.js.gz
In header I've included the css & js files like this:
<link rel="stylesheet" href="http://example.com/css/style.css" />
<script type="text/javascript" src="http://example.com/js/customjsfn.min.js"></script>
<script type="text/javascript" src="http://example.com/js/jquery.min.js"></script>
The styles are not applied properly. When I checked the response code using firebug, it returns 404 for my files.
Where I'm going wrong?