Response header - Connection: keep-alive, close - .htaccess

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>

Related

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.

How to do " If Modified Since "

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)

slider images loading twice after cache control

I have use following code in my .htaccess file for cache control in my joomla site.
########## Begin - ETag Optimization
## This rule will create an ETag for files based only on the modification
## timestamp and their size.
## Note: It may cause problems on your server and you may need to remove it
FileETag MTime Size
# AddOutputFilterByType is now deprecated by Apache. Use mod_filter in the future.
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
# Enable expiration control
ExpiresActive On
# Default expiration: 1 month after request
ExpiresDefault "now plus 1 month"
# CSS and JS expiration: 1 month after request
ExpiresByType text/css "now plus 1 month"
ExpiresByType application/javascript "now plus 1 month"
ExpiresByType application/x-javascript "now plus 1 month"
# 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"
cache control started working but i am facing a problem.
Now my slider image is loading two times before appearing. once image is loaded then it again loads ( just like refresh ), but other content is loading correctly.
Please help me out.
I am using DJ-ImageSlider extension of joomla. slider does not slide anything, it just show a single image as a banner.
ETags are difficult because they take precedence for caching in most browsers. You can change all the headers you want, but if the ETag associated with a file is always the same, caching will never work how you expect. In most situations, you should turn your ETag headers off.
Source - David Walsh
So to unset the ETag, you can use the following:
Header unset ETag
and remove this:
FileETag MTime Size
It's difficult to troubleshoot at a distance, but a few ideas you could try.
First make sure you are starting with a clean slate by clearing your browser cache and your Joomla cache, and repeat this step after any changes below.
If problem persists, try going to extensions > module manager > DJ-ImageSlider > Advanced and changing the caching setting.
If still no joy, perhaps play with the cache settings in System > Global Configuration > Cache Settings.
Good luck!

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