From my experience, I would like to share some ways to speed up page loading (apart from adding server hardware configuration). Hope it helps someone in need.
1. Enable HTTP2 and Brotli (if your webserver supports it)
2. Install and configure Zend Opcache to speed up PHP processing and reduce CPU load.
3. Install Memcached (or you can choose another, but I choose Memcached because it's easy to use )
4. Create a .htaccess file to cache the content and images. Eg:
5. Install and configure add-ons: Lazy Load 2.5.1 and Font Awesome Manager.
6. Enable cache in config.php
1. Enable HTTP2 and Brotli (if your webserver supports it)
2. Install and configure Zend Opcache to speed up PHP processing and reduce CPU load.
3. Install Memcached (or you can choose another, but I choose Memcached because it's easy to use )
4. Create a .htaccess file to cache the content and images. Eg:
Code:
Header set Strict-Transport-Security "max-age=10886400; includeSubDomains; preload"
# X-Content-Type nosniff
<IfModule mod_headers.c>
Header set X-Content-Type-Options nosniff
</IfModule>
<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"
</IfModule>
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript application/json application/x-font-ttf application/vnd.ms-fontobject image/x-icon
</IfModule>
###################################################
# Exception: Images
SetEnvIfNoCase REQUEST_URI \.(?:gif|jpg|jpeg|png)$ no-gzip dont-vary
# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Make sure proxies don't deliver the wrong content
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 2 month"
ExpiresByType application/atom+xml "access plus 2 hour"
ExpiresByType application/rdf+xml "access plus 2 hour"
ExpiresByType application/rss+xml "access plus 2 hour"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/ld+json "access plus 0 seconds"
ExpiresByType application/schema+json "access plus 0 seconds"
ExpiresByType application/vnd.geo+json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType image/vnd.microsoft.icon "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType text/html "access plus 1 minute"
ExpiresByType text/javascript "access plus 2 month"
ExpiresByType text/x-javascript "access plus 2 month"
ExpiresByType application/javascript "access plus 2 months"
ExpiresByType application/x-javascript "access plus 2 months"
ExpiresByType image/jpg "access plus 2 month"
ExpiresByType image/jpeg "access plus 2 month"
ExpiresByType image/gif "access plus 2 month"
ExpiresByType image/png "access plus 2 month"
ExpiresByType image/svg+xml "access plus 2 month"
ExpiresByType image/bmp "access plus 21 month"
ExpiresByType image/webp "access plus 2 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
ExpiresByType text/plain "access plus 2 month"
ExpiresByType text/x-component "access plus 2 month"
ExpiresByType application/manifest+json "access plus 2 week"
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
ExpiresByType application/pdf "access plus 2 month"
ExpiresByType application/x-shockwave-flash "access plus 2 month"
ExpiresByType application/vnd.ms-fontobject "access plus 2 month"
ExpiresByType font/eot "access plus 2 month"
ExpiresByType font/opentype "access plus 2 month"
ExpiresByType application/x-font-ttf "access plus 2 month"
ExpiresByType application/font-woff "access plus 2 month"
ExpiresByType application/font-woff2 "access plus 2 month"
ExpiresByType application/x-font-woff "access plus 2 month"
ExpiresByType font/woff "access plus 2 month"
ExpiresDefault "access plus 10 days"
</IfModule>
#Alternative caching using Apache's "mod_headers", if it's installed.
#Caching of common files - ENABLED
<IfModule mod_headers.c>
# 1 Month
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|svg|js|css|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
# 2 DAYS
<FilesMatch "\.(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>
# 2 HOURS
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz|html|ttf)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
# Set Keep Alive Header
# This *just* sets the header - maybe your hoster is not allowing this feature
# Please check if it is working with tools like http://www.webpagetest.org
<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>
# If your server don't support ETags deactivate with "None" (and remove header)
<IfModule mod_expires.c>
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
</IfModule>
6. Enable cache in config.php
Code:
//Used: Brotli
$config ['enableGzip'] = false;
//Cache
$config['cache']['enabled'] = true;
$config['cache']['css']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
'server' => [
['127.0.0.1',11211]
]
];
$config['pageCache']['enabled'] = true;
$config['pageCache']['lifetime'] = 600;
$config['cache']['context']['page']['provider'] = 'Memcached';
$config['cache']['context']['page']['config'] = [
'server' => [
['127.0.0.1',11211]
]
];