How can I tell that this Leverage browser caching is on? - .htaccess

I am trying to set the expiring date on the images/js/css ext.. on my site because i see in a tool that I am using Page Speed that it will help performance:
The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:
http://somesite.com/images/chat/footer_btn_chat_on.png (expiration not specified)
http://somesite.com/images/footer.jpg (expiration not specified)
http://somesite.localhost/inc/cache/all.js (expiration not specified)
So I added this to the htaccess and refreshed the page and still the (expiration not specified):
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 2 days"
ExpiresByType image/gif "access plus 60 days"
ExpiresByType image/jpg "access plus 60 days"
ExpiresByType image/png "access plus 60 days"
ExpiresByType application/x-javascript "access plus 60 days"
ExpiresByType text/css "access plus 60 days"
ExpiresByType image/x-icon "access plus 360 days"
</IfModule>
Do I need to turn anything on or is there a way to get this to work?

Related

Add Expires headers and image optimizaion not updating in siteground hosting

my website available in siteground hosting and i am updating image optimization as per suggestion Gtmetrix and add expire header but still not updating it showing up old
after i have also flush supercacher in hosting but still not updating
my expire header code like
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
ExpiresActive On
ExpiresDefault "access plus 1 year"
ExpiresByType text/html A0
ExpiresByType text/plain A0
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType text/css "access plus 14 days"
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType text/javascript "access plus 14 days"
ExpiresByType application/x-javascript "access plus 14 days"
ExpiresByType image/ico "access plus 14 days"
ExpiresByType image/jpg "access plus 14 days"
ExpiresByType image/jpeg "access plus 14 days"
ExpiresByType image/gif "access plus 14 days"
ExpiresByType image/png "access plus 14 days"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType text/html "access plus 14 days"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/atom+xml "access plus 1 hour"
</IfModule>
Any help would be appreciated.
Thanks.
My name is Georgi Ganchev and I am a Technical Support Supervisor at SiteGround.
I saw your thread and I decided to follow up.
The rules in your .htaccess are correct in general, but we recommend a longer expiration date set for your images, CSS and JS stored locally.
Please check the following article we have written about the most advised configuration:
https://www.siteground.com/kb/leverage-browser-caching/
In case the issue continues, please make sure you open a ticket through the User Area of your account with us and we will gladly help you out.
Best regards,
Georgi Ganchev
Technical Support Supervisor
Siteground.com
We were trying to get a wrong result. i was searching for a solution too but what i found after reading the test result with those lines code and without them:
this code is working but only with internal files.
this code will not work with external files(from other websites like google analytics js ...).
the test result will show you only the external files.
if you remove those lines of codes the result will be worst, and it will result in more files doesn't have an expired age.

Changes in htaccess Expires header not reflecting in browser

I have set all JS on my site to cache for one week. However, there are specific files that I need to be refreshed at a higher frequency. Hence I have used FilesMatch to effect the exception in my .htaccess file:
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 year"
# Data interchange
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
# Favicon (cannot be renamed!)
ExpiresByType image/x-icon "access plus 1 week"
# HTML components (HTCs)
ExpiresByType text/x-component "access plus 1 month"
# HTML
ExpiresByType text/html "access plus 0 seconds"
# JavaScript
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
# Manifest files
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Media
ExpiresByType audio/ogg "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 video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# Web feeds
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
# Web fonts
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>
<FilesMatch "^(ga\.js)$">
ExpiresActive on
ExpiresDefault "access plus 2 days"
</FilesMatch>
The exception file is at /sandboxassets/js/ga.js and the .htaccess I am working with is at the document root (/). However, the browser doesn't seem to honor this exception and gives the following header for the file in question:
Accept-Ranges:bytes
Access-Control-Allow-Origin:*
Age:0
Cache-Control:max-age=604800
Content-Encoding:gzip
Content-Length:11967
Content-Type:application/javascript
Date:Thu, 02 Mar 2017 15:03:55 GMT
Expires:Thu, 09 Mar 2017 15:03:55 GMT
Last-Modified:Thu, 02 Mar 2017 15:00:01 GMT
Server:Apache Phusion_Passenger/4.0.10 mod_bwlimited/1.4 mod_fcgid/2.3.9
Vary:Accept-Encoding,User-Agent
Via:1.1 varnish-v4
X-Varnish:18808880
604800 seconds is 1 week which is the default for all JS assets as defined in my .htaccess but I need it to be 172800 seconds (2 days). What am I doing wrong? Also, is there any way to tell the browser to refresh to the latest header? Opera is returning a 31536000 seconds (1 year) which is what I recently changed to 1 week for all JS!
Update: Using the following code is causing my site to break down completely with an error 500:
<Directory "/sandboxassets/js/">
AllowOverride All
<FilesMatch "ga\.js$">
Expires A172800
</FilesMatch>
<FilesMatch "tww\.js$">
Expires A172800
</FilesMatch>
</Directory>
I added it first inside <IfModule mod_expires.c> and then immediately after it and experienced the same error each time.
My first inclination is that you need to be able to use the 'AllowOverride' within a Directory target block to achieve the override of a specific file.
<Directory "/directory/to/your/file">
AllowOverride All
<FilesMatch "\.js$">
Expires A31536000
</FilesMatch>
</Directory>
Source(s):
http://www.websiteoptimization.com/secrets/advanced/caching-example.html
I highly recommend turning off CloudFlare to do the testing of this before you rule anything out.
It may also be beneficial to check out the answer to this question: https://webmasters.stackexchange.com/questions/9513/htaccess-execution-order-and-priority
I am adding this because I think that it is also possible that this is an ordering issue. .htaccess starts at the root and works its way through the directories.

Permanently delete/remove blog-articles perhaps automatically with rule?

I have an articles-blog and my articles may have a shelf-life of perhaps 1-2 weeks max. In my .htaccess I already have ExpiresByType rules (but the clutter in my MODx backend is still there and I do not understand the impact of these rules - code is below). I also have put my articles standard as indexable by the search engines.
When the shelf-life expires, I would like to permanently delete my articles. Now I do this manually and I have a whole lot of "red-crossed-out" articles titles in my back-end which makes me completely loose the overview.
My question is: What is MODx EVO best practise for my situation and is there an "automatic" way to permanently and completely (so no more red-crossed-out resource titles) remove expired articles from my MODx backend with pre-defined rules (for example, "if published time-period on the internet is 20 days then delete/remove article from MODx backend/database)"?
## Leverage Browser Caching ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## Leverage Browser Caching ##

Setting expiry on static resources with htaccess

just got to know that setting expiry dates for static resources make your site go fast and jump in rankings.
My question is:
Does browser checks create date of the static resource?
If I make change to a css before 1 month, does server sends fresh copy and browser refreshes its cache?
This is the code I added to htaccess:
<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>
From mod_expires documentation:
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.
Here is the syntax:
ExpiresByType type/encoding "base[plus num type] [num type] ..."
where base is one of:
access
now (equivalent to 'access')
modification
The plus keyword is optional. num should be an integer value [acceptable to atoi()], and type is one of:
years
months
weeks
days
hours
minutes
seconds
So if you write:
ExpiresByType image/gif "access plus 1 month"
Your file will be cached as long as visitors keep requesting it without interruption for more than a month, even if you modify it.
You should then write instead:
ExpiresByType image/gif "modification plus 1 month"
Then your file will be cached for a month as long as it is not modified, otherwise the cache will be updated.

Expires headers - why do I still get an error in Google Pagespeed Insights?

I've included the following section in my htaccess file. However I still get an error for 3 js files when I run Google PageSpeed Insights. The reason may be obvious but I can't see it.
Donald
# BEGIN Expire headers
ExpiresActive On
ExpiresDefault "access plus 1 week"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "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/x-javascript "access plus 604800 seconds"
ExpiresByType text/html "access plus 604800 seconds"
ExpiresByType application/xhtml+xml "access plus 1200 seconds"
# END Expire headers
Leverage browser caching for the following cacheable resources:
https://apis.google.com/js/plusone.js?onload=onLoadCallback (30 minutes)
http://google-analytics.com/ga.js (2 hours)
http://www.google-analytics.com/analytics.js (2 hours)
Is it possible that the particular file paths in the htaccess file are to blame? i.e. in one line I have text/javascript and in another I have application/x-javascript. Do I need to double up on those?

Resources