How to add leverage browser caching to my wordpress site - wordpress

I want to add leverage browser caching in my worspress site.
I have added code in my .htaccess file below:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
But i am not able to solve it.
Please help me to sove it.

That looks correct to me, although I normally do it like this:
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault A60
# Font files expire in 1 year
ExpiresByType font/otf A31449600
ExpiresByType font/x-woff A31449600
ExpiresByType application/font-woff2 A31449600
ExpiresByType font/ttf A31449600
# Image files expire in 1 month
ExpiresByType image/x-icon A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/gif A2592000
ExpiresByType application/x-shockwave-flash A2592000
# Stylesheet & Javascript files expire in 1 week
ExpiresByType text/css A604800
ExpiresByType text/javascript A604800
ExpiresByType application/javascript A604800
ExpiresByType application/x-javascript A604800
# HTML files do not expire
ExpiresByType text/html A0
ExpiresByType application/xhtml+xml A0
</ifModule>
Are you sure your host supports the "mod_expires" module?

Related

Unable to cache files in .htaccess file

I am trying to add expired headers to my .htaccess file and these files will not cache my .htaccess file is below. What am i doing wrong? My .htaccess file is in my root directory, do i need to add a .htaccess file in these subdirectories?
https://www.website.com/wp-content/plugins/woocommerce/assets/css/woocommerce-layout.css?x93196 (1 hour)
https://www.website.com/wp-content/plugins/woocommerce/assets/css/woocommerce-smallscreen.css?x93196 (1 hour)
https://www.website.com/wp-content/plugins/woocommerce/assets/css/woocommerce.css?x93196 (1 hour)
EXPIRES CACHING
ExpiresActive on
ExpiresDefault "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 year"
# Data interchange
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rdf+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 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/geo+json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/calendar "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
# Favicon (cannot be renamed!) and cursor images
ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
# HTML
ExpiresByType text/html "access plus 0 seconds"
# JavaScript
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
# Manifest files
ExpiresByType application/manifest+json "access plus 1 week"
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Markdown
ExpiresByType text/markdown "access plus 0 seconds"
# Media files
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType image/bmp "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType image/webp "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"
# WebAssembly
ExpiresByType application/wasm "access plus 1 year"
# Web fonts
# Collection
ExpiresByType font/collection "access plus 1 month"
# Embedded OpenType (EOT)
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType font/eot "access plus 1 month"
# OpenType
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType font/otf "access plus 1 month"
# TrueType
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/ttf "access plus 1 month"
# Web Open Font Format (WOFF) 1.0
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
# Web Open Font Format (WOFF) 2.0
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType font/woff2 "access plus 1 month"
# Other
ExpiresByType text/x-cross-domain-policy "access plus 1 week"

Switching language in polylang

I have a problem with polylang.
For example, the default language is PL and additional EN and DE. Everything is good, but when you switch to EN and close the browser, after entering the main domain again, EN is active. Clicking on PL it does not want to switch anything and in the address bar is always www.mypage.pl/en/. Even if I remove it from the address en it goes back to it.
Cleaning cookies in the browser does not give anything.
What may be the problem? How to fix it?
Thanks in advance for reply.
ok, I solved the problem by removing the following code from the htaccess file:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>

Wordpress - Expires Headers in .htaccess won't work

According to www.gtmetrix.com 2 components are without a far-expiration date:
I added at the end of my .htaccess
ExpiresActive on
ExpiresDefault "access plus 1 month"
"access plus 1 month"
# Web fonts
# Collection
ExpiresByType font/collection "access plus 1 month"
# Embedded OpenType (EOT)
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType font/eot "access plus 1 month"
# OpenType
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType font/otf "access plus 1 month"
# TrueType
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/ttf "access plus 1 month"
# Web Open Font Format (WOFF) 1.0
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
# Web Open Font Format (WOFF) 2.0
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType font/woff2 "access plus 1 month"
# Other
ExpiresByType text/x-cross-domain-policy "access plus 1 week"
and nothing happens. What can I do to set for these two componets expiration dates?
The scripts are from third party, not from you server. You have no control to add the expires headers.
optimize speed.
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>

How to fix this "expiration not specified" issue according to GTMatrix?

I have a website WeeTech Solution. And whenever i check my website on “GT Matrix” is show me the number of issue like...
• https://www.weetechsolution.com/css/content_slider_style.css (expiration not specified)
How to fix this issue?
you have to add this code in your htaccess file.
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
If your site in html & php then you can use .htaccess file with below code and upload this .htaccess file to main root.
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
If your site in .Net then yo can use staticContent inside Web.config file
code given below
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMaxAge="24:00:00" cacheControlMode="UseMaxAge" />
</staticContent>

How to Add Expires headers

I'm using this code in .htaccess
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/html "access plus 3 days"
ExpiresByType text/xml "access plus 1 seconds"
ExpiresByType text/plain "access plus 1 seconds"
ExpiresByType application/xml "access plus 1 seconds"
ExpiresByType application/rss+xml "access plus 1 seconds"
ExpiresByType application/json "access plus 1 seconds"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType image/x-ico "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType application/pdf "access plus 1 month"
<IfModule mod_headers.c>
Header unset ETag
Header unset Pragma
Header unset Last-Modified
Header append Cache-Control "public, no-transform, must-revalidate"
Header set Last-modified "Tue, 1 Aug 2016 10:10:10 GMT"
</IfModule>
</IfModule>
But gtmetrix.com and tools.pingdom.com shows 5 static components without a far-future expiration date.
http://fonts.googleapis.com/css?family=Lato:900
http://fonts.googleapis.com/css?family=Merriweather:regular,700
http://www.google-analytics.com/analytics.js
http://www.statcounter.com/counter/counter.js
http://c.statcounter.com/t.php?sc_project=11059157&java=1&security=2d5e45b2&u1=D82D61ABF18A4FF9620A96B3F31C97F5&sc_random=0.5705474616082253&jg=new&rr=1.1.1.1.1.1.1.1.1&resolution=1024&h=861&camefrom=&u=http%3A//hddregenerator.net/&t=HDD%20REGENERATOR.%2015%25%20Discount%20%7C%20HDD%20Regenerator%20for%20%2484.99.%20Free%20Demo%20download.%2030-day%20money%20back%20guarantee.%20Free%201%20year%20minor%20update.%20Unlimited%20license%20period.&rcat=d&rdom=d&rdomg=new&bb=1&sc_snum=1&sess=a181b5&p=0&invisible=1
How to add expire headers for these 5 components?!
I believe you can't add expire headers to those 5 components, simply because they aren't on your own server, and therefore you have no control over them.
If you're looking for a great expire headers plugin, I recommend Far Future Expiry Header.

Resources