1

I'm investigating my website on GTmetrix and currently I'm working on this case:

enter image description here

To make it working, I've added this to the .htaccess file which is located on the root of my project:

<IfModule mod_expires.c>
  ExpiresActive on

# Your document html
  ExpiresByType text/html "access plus 0 seconds"

# Media: images, video, audio
  ExpiresByType audio/ogg "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 video/mp4 "access plus 1 month"
  ExpiresByType video/ogg "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"

# CSS and JavaScript
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType text/css "access plus 1 year"
</IfModule>

But still GTmetrix gives a score of zero to this case of my website. Noted that my website uses Linux ubuntu 16.04 OS an appache web server.

Any idea how can I do that?

stack
  • 10,280
  • 19
  • 65
  • 117

2 Answers2

1

I am using following code, and it's working perfect for me:

# Add Expire headers
<IfModule mod_expires.c>
<Filesmatch "\.(jpg|jpeg|png|gif|js|css|swf|ico|woff|mp3)$">
  ExpiresActive on
  ExpiresDefault "access plus 30 days"
</Filesmatch>
</IfModule>
0

I did it using following commands:

sudo apt-get update
sudo apt-get install apache2-utils
sudo a2enmod cache
sudo a2enmod cache_disk
sudo a2enmod expires
sudo a2enmod headers
sudo service apache2 restart
stack
  • 10,280
  • 19
  • 65
  • 117