Mobile app version of vmapp.org
Login or Join
Fox8124981

: Cache control header specified in .htaccess is not working for static files I'm trying to use Google PageSpeed Insights to speed up my website - www.edmhunters.com. First off, here is what my

@Fox8124981

Posted in: #Apache #Apache2 #CacheControl #Htaccess

I'm trying to use Google PageSpeed Insights to speed up my website - edmhunters.com.
First off, here is what my .htaccess file looks like

# -----------------------------------------------------------------------
# Caching for 1 Year
# -----------------------------------------------------------------------
<FilesMatch ".(ico|svg|woff|eot|ttf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

# -----------------------------------------------------------------------
# Caching for 1 Week
# -----------------------------------------------------------------------
<FilesMatch ".(jpg|png|gif|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

# -----------------------------------------------------------------------
# Defining MIME types to ensure the web server actually knows about them
# -----------------------------------------------------------------------
<IfModule mod_mime.c>
AddType application/javascript js
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf ttc
AddType font/opentype otf
AddType application/x-font-woff woff
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
</Ifmodule>

# -----------------------------------------------------------------------
# Compressing output
# -----------------------------------------------------------------------
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</Ifmodule>


The Cache-Control header strangely is working only for media files and not static files.

Eg. The output of edmhunters.com/media/dj/images/deadmau5_2.jpg on redbot.org looks like this

HTTP/1.1 200 OK
Date: Sun, 14 Sep 2014 06:01:54 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Thu, 11 Sep 2014 13:52:29 GMT
ETag: "7391-502ca7aba5a6e"
Accept-Ranges: bytes
Content-Length: 29585
Cache-Control: max-age=604800, public
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: image/jpeg


While the output of edmhunters.com/static/img/bp-logo.9bf55788f1b6.jpg looks like this

HTTP/1.1 200 OK
Date: Sun, 14 Sep 2014 05:43:28 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Tue, 26 Aug 2014 05:43:32 GMT
ETag: 1409031812.62
Content-Length: 2592
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: image/jpeg


Also according to Google PageSpeed Insights for my homepage the HTML is minified, while Google PageSpeed Insights for another page says my HTML is not minified.

Why this different behaviour?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Fox8124981

1 Comments

Sorted by latest first Latest Oldest Best

 

@Megan663

I was serving my static files using Django while my media files using Apache. Serving my static files through Apache solved this issue.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme