.htaccessbrowser-cacheapache2.4mod-expiresmod-headers

mod_expires.c and mod_headers.c not working according to google pagespeed insights


When running a test on google pagespeed insights I get the error "Leverage browser caching"

What I have done

  1. Confirm that modules are enabled and working in Apache.

    As you can see here: http://noram.dk/phpinfo.php both mod_expires and mod_headers are installed and enabled. Also when i write sudo a2enmod expires and sudo a2enmod headers I get a "module already enabled" (And I did restart Apache2)

  2. Double confirm that modules are enabled and working in Apache.

    To double check this I have also tried removing the <ifModule mod_expires.c> and <ifModule mod_headers.c> lines from my .htaccess file (and the end tags ofc.), to confirm that I can still load the page without getting a server. I have also confirmed that my .htaccess file is working, by writing some junk in it, which does kill my website. (i also have working RewriteRule's in it)

So to summarize

  1. I am pretty sure the modules are installed and running.
  2. The htaccess file is working and being read by the server.
  3. I have inserted the code in the htaccess file as I should.

However, I keep getting the same feedback from google PageSpeed insights.

<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 2592000 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
</ifModule>

Solution

  • You can not do anything more. The results are as such because of

    http://static.hotjar.com/c/hotjar-98431.js?sv=5 (60 seconds)
    https://www.google-analytics.com/analytics.js (2 hours)
    

    since, none of those files are hosted on your own machine, you do not have control on their expiry headers. They will be cached as defined by the servers static.hotjar.com and google-analytics.com respectively.