Today we are configuring browser caching control on common Apache 2 Dedicated servers or VPS servers. Caching is a great tool to reduce server resource consumption, bandwidth utilization and provide a faster end-user experience to visitors. This includes, but is not limited to, both traditional Dedicated servers and Cloud VPS servers running a number of different Linux distributions:. The article assumes familiarity with the following basic system administration concepts:.
|Published (Last):||21 December 2017|
|PDF File Size:||1.90 Mb|
|ePub File Size:||15.65 Mb|
|Price:||Free* [*Free Regsitration Required]|
The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access. These HTTP headers are an instruction to the client about the document's validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this time has passed. After that, the cache copy is considered "expired" and invalid, and a new copy must be obtained from the source.
When the Expires header is already part of the response generated by the server, for example when generated by a CGI script or proxied from an origin server, this module does not change or add an Expires or Cache-Control header. The ExpiresDefault and ExpiresByType directives can also be defined in a more readable syntax of the form:.
The plus keyword is optional. For example, any of the following directives can be used to make documents expire 1 month after being accessed, by default:. The expiry time can be fine-tuned by adding several ' num type ' clauses:. Note that if you use a modification date based setting, the Expires header will not be added to content that does not come from a file on disk.
This is due to the fact that there is no modification time for such content. This directive enables or disables the generation of the Expires and Cache-Control headers for the document realm in question. That is, if found in an. If set to Off , the headers will not be generated for any document in the realm unless overridden at a lower level, such as an. If set to On , the headers will be added to served documents according to the criteria defined by the ExpiresByType and ExpiresDefault directives q.
Note that this directive does not guarantee that an Expires or Cache-Control header will be generated. If the criteria aren't met, no header will be sent, and the effect will be as though this directive wasn't even specified. This directive defines the value of the Expires header and the max-age directive of the Cache-Control header generated for documents of the specified type e.
The second argument sets the number of seconds that will be added to a base time to construct the expiration date.
The Cache-Control: max-age is calculated by subtracting the request time from the expiration date and expressing the result in seconds. The base time is either the last modification time of the file, or the time of the client's access to the document.
The difference in effect is subtle. If M is used, all current copies of the document in all caches will expire at the same time, which can be good for something like a weekly notice that's always found at the same URL. If A is used, the date of expiration is different for each client; this can be good for image files that don't change very often, particularly for a set of related documents that all refer to the same images i.
Note that this directive only has effect if ExpiresActive On has been specified. You can also specify the expiration time calculation using an alternate syntax , described earlier in this document. This directive sets the default algorithm for calculating the expiration time for all documents in the affected realm.
It can be overridden on a type-by-type basis by the ExpiresByType directive. See the description of that directive for details about the syntax of the argument, and the alternate syntax description as well. Copyright The Apache Software Foundation. Licensed under the Apache License, Version 2. Alternate Interval Syntax The ExpiresDefault and ExpiresByType directives can also be defined in a more readable syntax of the form: ExpiresDefault " base [plus num type ] [ num type ]
Configure Apache 2 to Control Browser Caching
How to configure caching with the mod_expires module
It provides for the generation of Expires headers according to user-specified criteria. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access. The Expires HTTP header is an instruction to the client about the document's validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this time has passed. After that, the cache copy is considered "expired" and invalid, and a new copy must be obtained from the source.
How can I cache my site with an .htaccess file?
View the following article for instructions on how to create an. If the file already exists, view the following articles for instructions on how to update it depending on if you're using an FTP client or SSH :. The following are default settings on DreamHost servers and do not need to be enabled. The examples above display DreamHost's default server settings.