Browser static caching


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. Opposite "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:
    Select "Own period (in hours)»And indicate 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 types of files, 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"
# cache css and js files for a week
<FilesMatch "\.(css|js)$">
  Header set Cache-Control "max-age=604800"
# disable caching of txt and zip files
<FilesMatch "\.(txt|zip)$">
  Header unset Cache-Control
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"