You can speed up page loading with a technique called caching. It deals with website files that are
stored in the browser's memory and do not have to be loaded again on every visit to the page, because the ones already stored in the browser's memory are used.
A guide to setting up the caching of static website files in the browser cache for faster page loading
The page caching described here means storing page files in the browser cache, most often on the computer's local hard drive. Not all resources (images, JavaScript, CSS styles, etc.) are then loaded from the web server, because the browser cache is used instead. Loading the whole page can therefore be significantly faster.
The behavior of the browser cache can be controlled with the relevant HTTP headers, either individually or by file type.
Option 1
On the Apache web server (which is what our web hosting uses), one way to set up caching is the mod_expires module, by writing the relevant rules into the .htaccess file.
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
ExpiresByType text/javascript A604800
ExpiresByType application/javascript A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
ExpiresByType image/x-icon A604800
ExpiresByType text/html A60
</IfModule>
- A31536000 is a value in seconds that specifies how long the file should be kept in the browser cache. When this time runs out, the files are marked as expired and are downloaded again the next time the page is loaded.
- ExpiresDefault is the value for all other undefined files and sets their maximum caching time.
- image/jpg is the type of the cached file; here you choose the file types you want to cache.
Option 2
As an alternative, you can use the following version. It not only compresses files but also caches additional files.
If this code does not work with our .htaccess, put the website in the domains/yourdomain_extension directory and place an .htaccess with this code there, plus any other code you have from the website's developer.
A proven .htaccess setup that includes compression:
# BEGIN Compress text files
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE \
text/html \
text/xml \
text/css \
text/plain \
image/svg+xml \
application/xhtml+xml \
application/xml \
application/rdf+xml \
application/rss+xml \
application/atom+xml \
text/javascript \
text/ecmascript \
application/javascript \
application/x-javascript \
application/ecmascript \
application/json \
application/x-font-ttf \
application/x-font-otf \
font/truetype \
font/opentype \
application/x-pointplus
</ifModule>
# END Compress text files
# BEGIN Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 2592000 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/jpg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 604800 seconds"
ExpiresByType application/javascript "access plus 604800 seconds"
ExpiresByType application/x-javascript "access plus 604800 seconds"
ExpiresByType text/html "access plus 604800 seconds"
ExpiresByType application/xhtml+xml "access plus 604800 seconds"
</ifModule>
# END Expire headers
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, max-age=360, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
# BEGIN Turn ETags Off
Header unset Pragma
FileETag None
Header unset ETag
# END Turn ETags Off
You can check that everything works correctly, and above all the change in page loading speed, with tools on one of these websites: