0

I have this in my .htaccess file.

<IfModule mod_expires.c>

    ExpiresActive on
    ExpiresDefault                                      "access plus 1 month"

  # CSS
    ExpiresByType text/css                              "access plus 1 month”

  # 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 week"
    ExpiresByType image/x-icon                          "access plus 1 week"

  # HTML
    ExpiresByType text/html                             "access plus 2 day”

  # JavaScript
    ExpiresByType application/javascript                "access plus 1 month”
    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 month"
    ExpiresByType image/bmp                             "access plus 1 month"
    ExpiresByType image/gif                             "access plus 1 month"
    ExpiresByType image/jpeg                            "access plus 1 month"
    ExpiresByType image/png                             "access plus 1 month"
    ExpiresByType image/svg+xml                         "access plus 1 month"
    ExpiresByType video/mp4                             "access plus 1 month"
    ExpiresByType video/ogg                             "access plus 1 month"
    ExpiresByType video/webm                            "access plus 1 month"

  # 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>

But on gtmetrix it still says: The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources

Ulrich Schwarz
  • 7,598
  • 1
  • 36
  • 48
Mareks
  • 135
  • 1
  • 2
  • 12
  • 1
    What are the following resources? Just CSS, everything? When you open the page in a browser with the developer tools' network tab open, what does the Headers section of the Repsonse of the files say? – Ulrich Schwarz Oct 28 '14 at 14:38
  • Does gtmetrix say which files aren't cached? [Google Page Speed](https://developers.google.com/speed/pagespeed/insights/) lists the files without/with too less caching. – Reeno Oct 28 '14 at 15:05
  • Tried google page speed, it gives the same results. Leverage Browser Caching for jpg, css, js files – Mareks Oct 28 '14 at 15:14
  • At least we know now which file types aren't cached. Try adding `AddType image/jpeg .jpg` before `ExpiresByType image/jpeg` and check again for jpg files. – Reeno Oct 28 '14 at 15:18
  • Are the files hosted on your server or are these files used by any third party services like Facebook Plugins, Twitter Widget etc.? You can't set any caching for ressources on other servers – Reeno Oct 28 '14 at 15:23
  • Did that, did not make any difference. png, jpg, gif, css, js not seeing as cached. All of those are my resources – Mareks Oct 28 '14 at 15:49
  • In the last comment you only listed jpg, css and js. Now you also list png and gif! Why can't you give us complete information from the beginning on? It's very hard to help you if you don't support us! Is anything cached from the file types in your .htaccess? – Reeno Oct 28 '14 at 15:53
  • I am sorry about that, there was just so many of those, No, nothing seems to be cached listed in .htaccess – Mareks Oct 28 '14 at 16:01
  • So if nothing at all is cached, are you sure the .htaccess is read? Is [AllowOverride](http://httpd.apache.org/docs/2.4/mod/core.html#allowoverride) active? – Reeno Oct 29 '14 at 09:10
  • I changed AllowOverride in httpd.conf file to AllowOverride All. Did not make any difference, maybe my paths are incorrect for the document folder? I have opened the ticket with hosting company to see if they can point me to right direction. My httpd.conf is is sitting beside .htaccess in the same folder, i do not know if server is picking that up and reading at all. – Mareks Oct 29 '14 at 13:38
  • .htaccess should sit in the same directory as your website files, httpd.conf is in another directory. They shouldn't be in the same directory – Reeno Oct 29 '14 at 21:56

1 Answers1

0

The syntax of your htaccess file is correct. Please make sure you

  • place the htaccess file in the right folder (i.e. the root folder of your project)
  • have the module mod_expires installed and enabled (see how to check if mod_expires is enabled
  • have set the desired expire time for all of your resources (which resources are ment by "the following resources"? You've set the expire header up to a year for some resources)
Community
  • 1
  • 1
Christian Fries
  • 444
  • 3
  • 12
  • Thanks for quick reply, i tried this command in terminal: apachectl -M both mime and headers are shared, do not not see expires module anywhere – Mareks Oct 28 '14 at 15:01
  • Compiled in modules: core.c mod_so.c http_core.c prefork.c – Mareks Oct 28 '14 at 15:51
  • If you haven't expires_module in your list, it's not installed/enabled. Ask your provider to install/enable it. And, as Reeno said, you have to place your .htaccess file in the folder your domain points to. – Christian Fries Oct 31 '14 at 23:48