2.4.1.1.5. Browser static caching

Attention!

Caching settings affect only the resources downloaded by the browser from our server. For resources loaded from third-party services, caching must be configured directly on the side of these services.

Using browser caching can speed up the loading of the site on repeat visits and reduce the number of requests to the server. The bottom line is that when you first visit the site, the server tells the browser how long it needs to store copies of the downloaded static files... When re-accessing the site, the browser already uses the local copies of the files saved in the cache and does not contact the server to get them.

  1. Openup site settings.
  2. Against «Caching» specify the storage period for static resources in the client's browser and save the changes:
    Select 1, 3, 8, or 12 hours, 1 day, 1 week, 1, 3, or 6 months, or 1 year:
    Pleaseselect «Own period (in hours)» and specify the required period in hours:
  3. Wait approximately 15-30 minutes for the changes to take effect.

Setting up caching through the control panel sets a single period for all types of static files. If you need to set individual caching periods for certain file types, do the following:

  1. Take away from list of static files file extensions for which you want to set an individual cache period.
  2. Write the caching directives in the file .htaccess.

Examples of caching directives:

# cache html and htm files for a day
<FilesMatch "\.(html|htm)$">
  Header set Cache-Control "max-age=43200"
</FilesMatch>
# cache css and js files for a week
<FilesMatch "\.(css|js)$">
  Header set Cache-Control "max-age=604800"
</FilesMatch>
# disable caching of txt and zip files
<FilesMatch "\.(txt|zip)$">
  Header unset Cache-Control
</FilesMatch>
 
ExpiresActive On
# default cache 30 seconds
ExpiresDefault "access plus 30 seconds"
# cache html and htm files for a day
ExpiresByType text/html "access plus 43200 seconds"
# cache css and js files for a week
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType application/javascript "access plus 604800 seconds"
Content