When doing website speed tests, I often see a comment along the lines of:
Serve static content from a cookieless domain
I want to ensure that data served from the static domain - files with extension JS, SVG, PNG, JPG and CSS - do not set cookies.
Here is a portion of my .htaccess:
<FilesMatch "\.(js|svg|png|jpg|css)$">
<IfModule header_module>
Header unset Cookie
</IfModule>
</FilesMatch>
I set a CNAME entry for static.example.com with the record www.example.com.
How can I ensure that either all files served from the subdomain, or any files with those extensions, don't set cookies?
Related
I am using plain domain name url to display homepage and within htaccess I have
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=3600, private, must-revalidate"
</FilesMatch>
to send Cache-Control header for html files. Unfortunatelly when just the domein is requested the FilesMatch obviously does not match, but I need to send the cache header anyway. ExpiresByType is not a solution as some files of type text/html are needed to keep uncached (forexample php script sending text/html data). Sending header by PHP is also not an option as the homepage html is cached in filesystem and served by apache directly (htaccess rule) without touching php. I am sure there must be some easy solution, but not able to figure out right now..thanks for help
I put my site on a Shared Hosting which uses Litespeed.
I know that it is possible to override the Connection Timeouts set on the Litespeed Server, locally in the .htaccess file.
<IfModule Litespeed>
RewriteEngine On
RewriteRule .* - [E=noconntimeout:1]
</IfModule>
I need to override the following directive: Max Request Body Size. Is it possible to override it inside .htaccess or only on the server?
Reason is I need to upload files bigger than 500 MB and it seems that this is blocked.
Unfortunately to change Max Request Body Size requires a Server Level change. There is currently no .htaccess rule to override it at this time.
You might want to contact your Shared Hosting Provider to see if they can increase the limit for you.
I have written this in my .htaccess file to leverage browser caching:
# 480 weeks caching
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch>
It is working well for files coming from mydomain.com url but the problem is that it does not affect the images coming from CDN URLs which are actually subdomains static.mydomain.com etc.
How can I leverage browser caching for images served through CDN?
Are you using S3? You can add this header in the S3 console for resources you want to cache:
CacheControl: max-age=999999
I tested my site using yslow and I got Grade B in Configure Entity tags.
I tried below condition in .htaccess and my site's Etags are removed, but not from JS included by CDN like validate.min.js
Header unset Pragma
FileETag None
Header unset ETag
Here is the image,
How to configure etags from Validate plugin from CDN.
It can be possible duplicate of How to off Etag with htaccess? except that here I am getting problem with js included by CDN.
I believe the answer is: you can't. Configurations like the ETags can only be controlled by the host, in this cast the CDN.
I think it's safe to not worry about this for your site. Loading that JS from a CDN is already a win, and this CDN is correctly supporting top performance rules like minification, gzip compression, and future expiration dates.
I've placed a simple cache control in my .htaccess file:
#cache css and javascript files for one week
<FilesMatch ".(js|css)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
When I test the desktop site at Google's Page Site tester: https://developers.google.com/speed/pagespeed/insights ... it shows the javascript and images are being cached properly. However, when I test my mobile website, the caching isn't working. My htaccess file is contained in the public_html directory alongside all my desktop files (ie. public_html/index.html, public_html/images/, public_html/css/, public_html/.htaccess etc.) My mobile site is contained here: public_html/mobile/.
Would I need to add a second .htaccess file to the mobile directory to make it work?
Thanks.
The best option is to use .htaccess file of html5 boilerplate. It is highly optimised for cache,gzip,cross-domain ajax plus a lot of features.
Also do check whether mod_deflate is on or not.
You don't need any additional .htaccess file just use a single file in the root of your directory.