1

I started using https://code.google.com/p/minify/ on my site to decrease the amount of http requests. But google's PageSpeed insights tool is telling me that the new reference link isn't being cached. A example of one of the new links that Minify created is this one:

<link type="text/css" rel="stylesheet" href="/min/f=css/responsee.css,css/components.css,css/animate.css,owl-carousel/owl.theme.css,owl-carousel/owl.carousel.css" />

My htaccess file has caching setup just fine and before I combined the .css files everything was being cached according to Pagespeed. Is this a bug or do I have to add a new line to my htaccess file?

<IfModule mod_expires.c>

    ExpiresActive on
    ExpiresDefault                                      "access plus 1 month"

   CSS
    ExpiresByType text/css                              "access plus 1 year"

  # Data interchange
    ExpiresByType application/atom+xml                  "access plus 1 hour"
    ExpiresByType application/rdf+xml                   "access plus 1 hour"
    ExpiresByType application/rss+xml                   "access plus 1 hour"

    ExpiresByType application/json                      "access plus 0 seconds"
    ExpiresByType application/ld+json                   "access plus 0 seconds"
    ExpiresByType application/schema+json               "access plus 0 seconds"
    ExpiresByType application/vnd.geo+json              "access plus 0 seconds"
    ExpiresByType application/xml                       "access plus 0 seconds"
    ExpiresByType text/xml                              "access plus 0 seconds"

  # Favicon (cannot be renamed!) and cursor images
    ExpiresByType image/vnd.microsoft.icon              "access plus 1 year"
    ExpiresByType image/x-icon                          "access plus 1 year"

  # HTML
    ExpiresByType text/html                             "access plus 0 seconds"

  # JavaScript
    ExpiresByType application/javascript                "access plus 1 year"
    ExpiresByType application/x-javascript              "access plus 1 year"
    ExpiresByType text/javascript                       "access plus 1 year"

  # Manifest files
    ExpiresByType application/manifest+json             "access plus 1 year"

    ExpiresByType application/x-web-app-manifest+json   "access plus 0 seconds"
    ExpiresByType text/cache-manifest                   "access plus 0 seconds"

  # Media files
    ExpiresByType audio/ogg                             "access plus 1 week"
    ExpiresByType image/bmp                             "access plus 1 week"
    ExpiresByType image/gif                             "access plus 1 week"
    ExpiresByType image/jpeg                            "access plus 1 week"
    ExpiresByType image/png                             "access plus 1 week"
    ExpiresByType image/svg+xml                         "access plus 1 week"
    ExpiresByType image/webp                            "access plus 1 week"
    ExpiresByType video/mp4                             "access plus 1 week"
    ExpiresByType video/ogg                             "access plus 1 week"
    ExpiresByType video/webm                            "access plus 1 week"

  # Web fonts

    # Embedded OpenType (EOT)
    ExpiresByType application/vnd.ms-fontobject         "access plus 1 month"
    ExpiresByType font/eot                              "access plus 1 month"

    # OpenType
    ExpiresByType font/opentype                         "access plus 1 month"

    # TrueType
    ExpiresByType application/x-font-ttf                "access plus 1 month"

    # Web Open Font Format (WOFF) 1.0
    ExpiresByType application/font-woff                 "access plus 1 month"
    ExpiresByType application/x-font-woff               "access plus 1 month"
    ExpiresByType font/woff                             "access plus 1 month"

    # Web Open Font Format (WOFF) 2.0
    ExpiresByType application/font-woff2                "access plus 1 month"

  # Other
    ExpiresByType text/x-cross-domain-policy            "access plus 1 week"

</IfModule>

EDIT:

Here is the header:

GET /min/f=css/responsee.css,css/components.css,css/animate.css,owl-carousel/owl.theme.css,owl-carousel/owl.carousel.css HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
Accept: text/css,*/*;q=0.1
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://example.com/
Cookie: PHPSESSID= -removed-; 
sc_is_visitor_unique=rx10296953.1429464775.24A3E18F98904F802719FEC9140DFAFF.30.22.19.17.10.6.3.1.1
Connection: keep-alive
If-Modified-Since: Sun, 19 Apr 2015 15:43:07 GMT
If-None-Match: "pub1429458187;gz"
Cache-Control: max-age=0

HTTP/1.1 304 Not Modified
Date: Sun, 19 Apr 2015 17:34:10 GMT
Server: Apache
Connection: Keep-Alive
Keep-Alive: timeout=15, max=99
Etag: "pub1429458187;gz"
Expires: Sun, 19 Apr 2015 18:04:10 GMT
Cache-Control: max-age=1800
Vary: Accept-Encoding,User-Agent
Crecket
  • 113
  • 4
  • Is this returning a text/css Content-Type? – MrWhite Apr 19 '15 at 17:01
  • @w3d the tool automatically generates the line of text to enter into your page. The link I posted is the exact link that the tool generated so I'm guessing it is considered text/css type but I could be wrong – Crecket Apr 19 '15 at 17:16
  • You can see what Content-Type header your server is responding with by examining the request/response in the browser. This header works with the ExpiresByType directive you have in .htaccess. In fact you should be examining the HTTP response headers to see why this resource is not being cached. – MrWhite Apr 19 '15 at 17:24
  • @w3d I edited my orginal post and added the header – Crecket Apr 19 '15 at 17:45
  • As you can see from the response headers: "304 Not Modified" - this resource is being cached by the browser (which is also probably why there is no Content-Type header in the response). The Cache-Control: max-age=1800 header is telling the browser to cache this response for 30 minutes. I would assume this is being set by the Minify script - which will override mod_expires (which will only set the header if it doesn't already exist). – MrWhite Apr 19 '15 at 18:08
  • I just started with all this so this is really usefull, thanks allot :) If you post this as a answer ill put it as the answer btw – Crecket Apr 19 '15 at 18:13

1 Answers1

0

You can see from the response headers (after the edit): "304 Not Modified" - this indicates that the resource is being cached by the browser after all (which is also probably why there is no Content-Type header in this particular response).

However, this resource is "only" being cached for 30 minutes, which might be why the PageSpeed tool is complaining?

The Cache-Control: max-age=1800 header is telling the browser to cache this response for 30 minutes (and this matches the Expires header when compared with the timestamp of the request).

I would assume the Cache-Control headers are being set by the Minify script - which will override mod_expires (which will only set the header if it doesn't already exist).

MrWhite
  • 42,784
  • 4
  • 49
  • 90