The Apache expires
header governs how long web browsers can keep
cached copies of your web content before requesting it again from the
server. Configuring this header can decrease the server load and speed
up your website.
For example, you set the expiration period to 10 days. A visitor browses
your website, requesting its index.html
page. The visitor’s web
browser stores a copy of the page in its cache, and for the next 10 days
it would serve the cached copy every time the visitor browses your
website. On the eleventh day, if the page is requested again, the
browser would request the page again from the server, because the one it
stored in the cache is past its expiration date.
When configuring the expires
header for websites featuring dynamic
content, we recommend enabling the response with Expires headers for
static files only option. Otherwise, all content, including dynamic
content, will be stored in the visitors’ browsers’ cache for the
duration of the expiration period. This is not recommended because the
dynamic content is, as a rule, updated frequently.
Note: The “Expires” header feature requires that mod_expires
is
enabled in
Apache.
To configure the “Expires” header:
- Go to Websites & Domains > Apache & nginx Settings.
- Under Expires, select the Enter custom value radio button.
- Specify the desired expiration period (the recommended length of the
expiration period is 14 days). - If your website features dynamic content, make sure that the
response with Expires headers for static files only checkbox is
selected. - Click OK.
Note: If nginx is enabled, only files served by Apache will have the
expires header. If the Smart static files processing checkbox is
selected, which files are treated as static is determined by the
Apache and nginx default configurations. If the Serve static files
directly by nginx checkbox is selected and any file extensions are
specified, nginx only serves the files with the specified extensions.