Efficient Cache Policy on Static Assets

Page Speed Insights

Google’s PageSpeed Insights is a tool often used by webmasters to analyze the attributes of a web page. The service evaluates the performance of the page on both mobile and desktop devices, and provides insights in terms of improving page speed. The ultimate objective being a better experience for visitors to that page.

The results of the webpage analysis is presented to users in the form of audits, which fall into three categories: opportunities, diagnostics, and passed audits:

  • Opportunities: consist of recommendations to improve the speed it takes to render a page
  • Diagnostics: provides insights into how well the page adheres to current best practices
  • Passed Audits: presents a listing of the audit items earning a passing grade in terms of both speed and best practices

Uses efficient cache policy on static assets

If you’re running a LitesSpeed or OpenLiteSpeed server, you may have encountered a suggestion that talks about the cache policy for static assets. In this example, the lack of a policy for fontello.woff fonts. You might be tempted to resolve this problem using the LiteSpeed Cache plugin for WordPress, but found no matter which settings you changed, the problem remained.

If you’ve encountered this issue. the following process should resolve this recommendation. The first step is to SSH into the server and gain root privileges. (If you don’t have access to the server via the command line, you can ask your host for assistance.) The next step is to locate the LightSpeed configuration files:

# cd /usr/local/lsws/conf

And list the files in the directory:

# ls -all

At this point, we are looking for two files: mime.properties and httpd-expires.conf. We need to make sure the application, in this case fontello.woff, is listed in the mime.properties file. Using your favorite editor, you can view the contents of that file:

# nano mime.properties

In mime.properties, you should see a long list of mime types, among which might be the following:

woff    = application/font-woff
woff2   = font/woff2
woff3   = font/woff
woff4   = application/font-woff2

If woff = application/font-woff does not appear in the list, then add it and save the file. The next step is to edit the httpd-expires.conf file:

# nano httpd-expires.conf

That file will likely include something like:

expires {
    enableExpires           1
    expiresByType           image/*=A604800,text/css=A604800,application/x-javascript=A604800,application/javascript=A604800,font/*=A604800,application/x-font-ttf=A604800

Here we can see that application/font-woff is not included, so we add it and save the file:

expires {
    enableExpires           1
    expiresByType           image/*=A604800,text/css=A604800,application/x-javascript=A604800,application/javascript=A604800,font/*=A604800,application/x-font-ttf=A604800,application/font-woff=A604800

The final step is to restart the OpenLiteSpeed / LiteSpeed server . In the case of a RedHat, Centos, AlmaLinux, or Rocky Linux server, this is done as follows:

# systemctl restart lsws

Leave a Comment