2.4.1.1.5. Browser caching of static content

Attention!

Caching settings only affect resources that the browser downloads from our server. For resources that are downloaded from third-party services, caching must be configured directly on the side of those services.

Using browser caching can speed up the loading of a site on subsequent visits and reduce the number of requests to the server. The essence is that when you visit a site for the first time, the server tells the browser how long it should store copies of the downloaded static files in its cache. When the site is accessed again, the browser uses the local copies of the files stored in the cache and does not contact the server to get them.

  1. Open the "Site settings" section.
  2. In the "Caching" field, specify the period for storing 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 specify the desired period in hours:
  3. Wait approximately 15-30 minutes for the changes to take effect.

Configuring caching via 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. Remove from the static files list the file extensions for which you want to set an individual caching period.
  2. Add caching directives to the .htaccess file.

Examples of caching directives:

# cache html and htm files for one 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 one 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

    (1)