Adding Expires Headers to Minimize Requests & Transfers

Website visitors and search engines love sites that perform better. A factor that can affect this rank is how assets like images, CSS and JS files are cached by visitors’ web browsers.

During development, you may not want the following settings on for testing. Once a site goes live, however, the example below will increase your Page Speed score—you may wish to set a longer expires line like 14d for two weeks, or 30d for thirty days. Apply the following to your Web Rules to leverage browser caching. 

location ~* \.(?:ico|css|js|jpe?g|png|gif|svg|pdf|mov|mp4|mp3|woff)$ {
    expires 7d;
    add_header Pragma public;
    add_header Cache-Control "public";
    gzip_vary on;
}
location / {
    try_files $uri $uri/ @modx-rewrite;
}

 

Note: This is not enabled by default to make developing sites more straightforward, by not requiring force-refresh to see changes in CSS and images, for example.

 

 

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.