How to do " If Modified Since " - .htaccess

I verify my website with a SEO tools, and between the errors that I get the " If Modified Since "
When I learn about it I found that about caching, and if you modify something you drop the cache
about caching I have this .htaccess code
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
But I want to add the If Modified Since any solution ?
(I try to search about it but without any results)

Related

Cache policy in htaccess not being heeded to by reporting tools

There are many questions out there LIKE this PageSpeed Insights wrongly reporting cache policy But none address the issue of simply ignoring the cache policies that are stated by the .htaccess file. Normally I wouldn't worry so much about this, as our sites paint completely in under 2 seconds and user experience is great. But Management cares about pretty graphs and reports.
I have the following caching policies:
ExpiresActive On
# Images
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
# Video
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"
ExpiresByType video/m4v "access plus 1 year"
# CSS, JavaScript
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
# Others
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
I want to point out one in particular since it makes it easy to point out the problem:
ExpiresByType video/m4v "access plus 1 year"
If you visit the site and view the headers for said file:
You can clearly see that the setting is being sent by header and is, thus, properly configured for a 1 year policy. HOWEVER .. When using Insights, OR Lighthouse individually they both report 30 days:
Not to mention all the other policies that are transferring properly in the header, but being completely ignored by LightHouse and Insights .. Does anyone have any answer for "why" this is happening? It's infuriating that even though the headers are obviously correctly sent, Lighthouse ignores them.
I have even tried something like this to no avail:
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|mp4|m4v|css|js)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
But I don't think that will make a difference, since the headers are, in fact, being sent correctly.

Caching Lifetime "Best Practice" for Google Pagespeed

im currently facing some problems while improving page speed of a customer website. Google says: There are several resources, which are not fitting with the perfect cache-lifetime. They are not providing any best practices for that, so which value is for which resource the best?
This is currently my htaccess part:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/ogg "access plus 1 year"
ExpiresByType video/webm "access plus 1 year"
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/x-component "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresDefault "access 1 month"
</IfModule>
Google says: its better, but not good enough. So, is there anybody who can provide me some info or best practise for the perfect resource caching time? I would really appreciate that.
Google recommends 1 year for static assets.
We recommend a minimum cache time of one week and preferably up to
one year for static assets, or assets that change infrequently. If
you need precise control over when resources are invalidated we
recommend using a URL fingerprinting or versioning technique...
Source: https://developers.google.com/speed/docs/insights/LeverageBrowserCaching
As stated you need to make sure you implement cache busting techniques to ensure you don't inadvertently serve old CSS etc.
It is calculated on a non linear scale (i.e. 6 months is not twice as good as 3 months) so it is not possible to give an exact numer of days but 6 months for all assets would pass, whereas all assets except CSS at 1 year with CSS at 1 week may not.
If you change your CSS and JS cache time to 1 year I would imagine this diagnostic would not show.
Always bear in mind these are recommendations and best practices, you have to do what is best for your site so ensure that any cache length you set is right for your use case.

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.

htaccess file, cache, and site speed

In my default .htaccess file are the following lines :
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
1- What does mean : access plus ?
2-What happens if I change :
ExpiresByType image/jpeg "access plus 1 month"
to
ExpiresByType image/jpeg "access plus 6 months"
3-In case I change one jpeg image on the site, what image will see a visitor who visited the site within the last 2 weeks :
the previous image ?
the new image ?
4-Of course I wonder the same thing for css and javascript changes.
Thank you in advance for any information on this matter.
Kind Regards,
Patrick

Response header - Connection: keep-alive, close

I am trying to up our page speed and the recommendation is to have the Connection: Keep-alive. However, no matter what i try to do i have "keep-alive, close". And I can not find out where the "close" value comes from.
Neither can i remove it. Anyone experience the same thing?
I have this in my .htaccess:
Header set Connection keep-alive
Best regards,
Rasmus
Your server appears to have keep-alive disabled for either your account or the whole server to ensure the maximum number of sockets are available at all times Rasmus.
This is of course a double edged sword because most websites typically make between 10-30 requests when pulling down all the resources needed to build a page providing nothing is cached, which is a lot of opening and closing overhead. Even if it needed to pull down 50 additional resources setting it like this:
<ifModule mod_headers.c>
Header set Connection keep-alive
Keep-Alive: timeout=5, max=100
</ifModule>
would be more then enough time to get the job done. But I'm sure it's standard practice to disable this feature in order to make sure it's not abused. Just ask your admin if they can hook you up.
My recommendation would be don't worry about the Keep-Alive header, you get way more bang for your buck by making sure your static files are being cached properly anyway. If your admin enables it for you down the road that's great but this is what I put in my .htaccess file to help reduce the number of requests it receives by 60%-80%.
<IfModule mod_expires.c>
# Enable expiration control
ExpiresActive On
# Default expiration: 1 hour after request
ExpiresDefault "now plus 1 hour"
# CSS and JS expiration: 1 week after request
ExpiresByType text/css "now plus 1 week"
ExpiresByType application/javascript "now plus 1 week"
ExpiresByType application/x-javascript "now plus 1 week"
# Image files expiration: 1 month after request
ExpiresByType image/bmp "now plus 1 month"
ExpiresByType image/gif "now plus 1 month"
ExpiresByType image/jpeg "now plus 1 month"
ExpiresByType image/jp2 "now plus 1 month"
ExpiresByType image/pipeg "now plus 1 month"
ExpiresByType image/png "now plus 1 month"
ExpiresByType image/svg+xml "now plus 1 month"
ExpiresByType image/tiff "now plus 1 month"
ExpiresByType image/vnd.microsoft.icon "now plus 1 month"
ExpiresByType image/x-icon "now plus 1 month"
ExpiresByType image/ico "now plus 1 month"
ExpiresByType image/icon "now plus 1 month"
ExpiresByType text/ico "now plus 1 month"
ExpiresByType application/ico "now plus 1 month"
ExpiresByType image/vnd.wap.wbmp "now plus 1 month"
ExpiresByType application/vnd.wap.wbxml "now plus 1 month"
ExpiresByType application/smil "now plus 1 month"
# Audio files expiration: 1 month after request
ExpiresByType audio/basic "now plus 1 month"
ExpiresByType audio/mid "now plus 1 month"
ExpiresByType audio/midi "now plus 1 month"
ExpiresByType audio/mpeg "now plus 1 month"
ExpiresByType audio/x-aiff "now plus 1 month"
ExpiresByType audio/x-mpegurl "now plus 1 month"
ExpiresByType audio/x-pn-realaudio "now plus 1 month"
ExpiresByType audio/x-wav "now plus 1 month"
# Movie files expiration: 1 month after request
ExpiresByType application/x-shockwave-flash "now plus 1 month"
ExpiresByType x-world/x-vrml "now plus 1 month"
ExpiresByType video/x-msvideo "now plus 1 month"
ExpiresByType video/mpeg "now plus 1 month"
ExpiresByType video/mp4 "now plus 1 month"
ExpiresByType video/quicktime "now plus 1 month"
ExpiresByType video/x-la-asf "now plus 1 month"
ExpiresByType video/x-ms-asf "now plus 1 month"
</IfModule>

Resources