Question

Mod expires configuration and or installation

Posted February 20, 2020 349 views
LAMP Stack

Hi

I performed a pagespeed test it appears that I do not have Mod expires or it is not configured. I moved this site from a shared host and had this configured in my .htaccess file. However, I now have just realized that this probably isn’t installed or configured on my Ubuntu Lamp stack.

How would I go about this

Cheers

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi @albertramsbottom,

I believe mod_expires comes automatically when you install Apache however you can check it like so

apachectl -M 

If you can’t find it in the presented list, try using the following command to enable it

a2enmod headers
a2enmod expires
systemctl restart apache2

That’s it, you now have mod_expires enabled.

Regards,
KDSys

  • Yes thanks I have done that but when i go to https://gtmetrix.com/ and stick in my sites it says

    Leverage browser caching for the following cache-able resources:
    
    https://assets.what3words.com/css/w3w-glyphicon.css (expiration not specified)
    https://assets.what3words.com/fonts/w3w-grid.woff (expiration not specified)
    https://www.google.com/recaptcha/api.js?onload=cf7srLoadCallback&render=explicit (5 minutes)
    https://www.google.com/recaptcha/api2/webworker.js?hl=en&v=n1ZaVsRK4TYyiKxYab0h8MUD (5 minutes)
    https://chimpstatic.com/mcjs-connected/js/users/c6ea18472c6fdfee5b5f4fb5c/e0b042c96c625f7c02c6b6167.js (12 minutes 30 seconds)
    https://secure.oneallcdn.com/css/api/socialize/themes/wordpress/modern.css (2 hours)
    https://secure.oneallcdn.com/css/api/themes/beveled_w35_h35_wc_v1.css (2 hours)
    https://streetdecalscouk.api.oneall.com/socialize/library.js (4 hours)
    

    Does this mean I need to addreass each file type?

    My cache header part of my .htaccess is

    Thanks

    <IfModule mod_expires.c>
        ExpiresActive on
        #ExpiresDefault                                      "access plus 1 month"
    
      # CSS
        ExpiresByType text/css                              "access plus 1 year"
    
      # Data interchange
        ExpiresByType application/json                      "access plus 0 seconds"
        ExpiresByType application/xml                       "access plus 0 seconds"
        ExpiresByType text/xml                              "access plus 0 seconds"
    
      # Favicon (cannot be renamed!)
        ExpiresByType image/x-icon                          "access plus 1 week"
    
      # HTML components (HTCs)
        ExpiresByType text/x-component                      "access plus 1 month"
    
      # HTML
        ExpiresByType text/html                             "access plus 0 seconds"
    
      # JavaScript
        ExpiresByType application/javascript                "access plus 1 year"
    
      # Manifest files
        ExpiresByType application/x-web-app-manifest+json   "access plus 0 seconds"
        ExpiresByType text/cache-manifest                   "access plus 0 seconds"
    
      # Media
        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"
    
      # Web feeds
        ExpiresByType application/atom+xml                  "access plus 1 hour"
        ExpiresByType application/rss+xml                   "access plus 1 hour"
    
      # Web fonts
        ExpiresByType application/font-woff                 "access plus 1 month"
        ExpiresByType application/vnd.ms-fontobject         "access plus 1 month"
        ExpiresByType application/x-font-ttf                "access plus 1 month"
        ExpiresByType font/opentype                         "access plus 1 month"
        ExpiresByType image/svg+xml                         "access plus 1 month"
    </IfModule>
    
    • Hi @albertramsbottom,

      According to GTMetrix, you should be able to use the following

      <IfModule mod_expires.c>
        ExpiresActive On
      
        # Images
        ExpiresByType image/jpeg "access plus 1 year"
        ExpiresByType image/gif "access plus 1 year"
        ExpiresByType image/png "access plus 1 year"
        ExpiresByType image/webp "access plus 1 year"
        ExpiresByType image/svg+xml "access plus 1 year"
        ExpiresByType image/x-icon "access plus 1 year"
      
        # Video
        ExpiresByType video/mp4 "access plus 1 year"
        ExpiresByType video/mpeg "access plus 1 year"
      
        # CSS, JavaScript
        ExpiresByType text/css "access plus 1 month"
        ExpiresByType text/javascript "access plus 1 month"
        ExpiresByType application/javascript "access plus 1 month"
      
        # Others
        ExpiresByType application/pdf "access plus 1 month"
        ExpiresByType application/x-shockwave-flash "access plus 1 month"
      </IfModule>
      

      I can see you have most if not all applied but please make sure you do and test it with GTMerix one more time. Please be aware there can be cache on GTMetrix as well.

      Regards,
      KDSys

Submit an Answer