Add Expires headers
How do I add Expires Header to the .htaccess file?
Is the error “Add Expires headers” displayed in GTmetrix or Pingdom?
What is the Expires header?
What are the steps to add expired headers to .htaccess?
When is the right time to expire files and cache?
Understand how to add Expires headers to the .htaccess file.
One of the most common errors when testing the webpage on Pingdom or GTmetrix is: Add Expires headers.
When a user visits your web site on the web, the browser automatically downloads a set of files. Each of these files has an expiration date and remains in the cache for a specified time. If the user decides to revisit other pages on your website or website, not all files need to be reloaded. If the file expiration time is too short, the “Add Expires Headers” error will be displayed.
How does Expires Header work?
Expired headers command the browser to download and save these files. The reason for this is to reduce the sending and receiving between the computer and the server (ie the website) and to use the cached data.The reason for this is to reduce the sending and receiving between the computer and the server (ie the website) and to use the cached data.
Each time a new user calls your website, all the files are requested by the server. Each request (for each individual file) requires different loading time depending on the greetings of the file. However, storing certain files in memory reduces the number of requests. This will load the website faster.
# How long should the data remain in the cache of the browser?
To prevent users from re-downloading shared files, an expiration date should be defined for these files. The defined expiration date tells the browser which file should be requested by the server and which file should be requested by the cache.
Which files are stored in the cache?
The first step is to determine which files are updated frequently and which are rarely updated.
Files that are rarely updated:
Web fonts, fonts
Files that are updated more frequently:
How do I add Expires headers to the .htaccess file to avoid the “add expires headers” error?
Add Expires headers to the .htaccess file:
The .htaccess file is often a hidden file in your root directory (root directory). Be sure to back up this file before changing anything. If something goes wrong, you can restore the saved file.
1. Download your .htaccess file. If the file is hidden, enable “Show hidden files” in your FTP.
2. Open your .htaccess file in an editor (Editor or Editor ++) and add your code with the expiration dates. This can be determined individually according to your requirements.
We use e.g. the following code, you can copy it and use it for your .htaccess:
The query <IfModule mod_expires.c > checks if the necessary server module is installed.
ExpiresActive On will turn on the module for your webpage, then it will tell you which types of files should be cached and for what period of time. The time is given in the form “from last access for period X”, in the example “access plus 1 weeks” thus “from access for a week”. If the set period has expired, the file in the browser cache will be replaced by the current version of your website.
Make sure that the time is always defined in the majority, so that an “s” is at the end (weeks, months, …). The timestamp values are listed in the official Apache webserver documentation: http://httpd.apache.org/docs/2.0/mod/mod_expires.html#AltSyn
3. After making the changes to the .htaccess file, remember to save it and upload it back to the root of your web site, unless you have made a direct change on the server.
How long should the expiration time of files be set?
The duration of the cache can be set in years, months, weeks, days, hours and even seconds.
The expiration date of each file should be determined based on the time it is used / requested.
The expiration date of images can be set to about a year, as they usually do not change and take up the loading of images most of the time.