问题
I'm struggling in something i don't know at all. When the time i ping my website, i got this result: [Serve the following static resources from a domain that doesn't set cookies:]
. And, this result caused from the images which i used for background images. I tried to google about this topic but all the answers seem to be difficult to understand of. Does anyone here knows about it and any simple solution to fix it up?
回答1:
Generally, when you are serving content such as images, JavaScript, CSS, there is no reason for a HTTP cookie to accompany it, as it creates additional overhead. That is why a lot of tools report this. Here are two quick and easy options:
Option 1 - Use a CDN
Use a CDN to host your images which has the ability to ignore cookies as well as strip cookies which will completely prevent the client from receiving the Set-Cookie response header. Note: You can't disable cookies on Cloudflare.
Option 2 - Point Static Assets to New Domain
This is an example with WordPress.
- First, create a subdomain such as static.domain.com. This is where you will deliver all your files from.
- Point your subdomain to your /wp-content directory with a CNAME.
- Edit your wp-config.php file to reflect the following:
define("WP_CONTENT_URL", "http://static.domain.com");
define("COOKIE_DOMAIN", "domain.com");
See more in this post on how to fix the Serve Static Content From a Cookieless Domain warning.
回答2:
I'll try and give a very high level overview as you haven't given a lot of specifics in your question. Please be aware that there are many ways to solve this issue, and I will attempt to give one solution which I think is easy to understand.
That message is suggesting that if your website is www.company.com, then you should load static content from www.companycdn.com. And that new site (www.companycdn.com) is a simple static website that does not serve cookies.
To do this, you need to upload your static resource (e.g. images) to the second domain.
And then update the paths of images to the new domain. For example, instead of this: <img src="logo.jpg"/>
, you should change it to this <img src="//www.companycdn.com/logo.jpg"/>
This answer has more information: https://webmasters.stackexchange.com/questions/1772/how-do-i-set-up-a-cookie-less-domain
回答3:
If you are new to this. I will like you to tell you first that once you set a cookie it will be sent to server in each and every request.
The default nature is, it will be sent to all requests going to your parent domain and all of it's subdomains. That is how cookies impact everything.
So to make your website speed better you don't overload your http requests. If you trim down the cookies it will be better.
Now let's move on to how to do it. Use a different domain name, you can also restrict some subdomains from setting cookie but it can be a devops liability in long run.
For example Quikr has parent domain http://www.quikr.com/ but loads all static resources from kuikr.com
http://teja1.kuikr.com/public/images/dist/RECarousel/hospitality_jobs.png
I hope this helps. Thanks !
回答4:
@Brian Jackson described very well, how to actually achieve this. Most people are asking this question, after running tools like Pagespeed Insights, GtMetrix, Pingdom, etc. and here is what’s recommended:
The main factor for better search engine ranking is the actual loading speed (the optimization checklist is secondary). Moving your static resources to a subdomain will increase page load time instead of decreasing it (in most cases, especially if we’re talking about a few files, css, js and some images). Even using a CDN will have an adverse effect, in case you’re only serving some stylesheets, js resources and few images, just to score higher on those tools.
If you have a lot of images or very large static resources, it’s recommended to use a fast CDN, that will help in many ways.
If you’re doing this to score higher on the tools checklist, I would take @Brian Jackson advice and compare before-and-after with Google’s Pagespeed Insights. That will give you the answer if your changes did benefit page loading speed or made it worse. Never sacrifice loading speed for checking another box, these tools are generic, not suitable for every specific website or web-app.
On the image above, I pointed out the recommendation by YSlow. When I move the assets in question to a cookie-free subdomain, both YSlow and Pagespeed Insights optimization score jumps to 100% however, the loading speed drops slightly (100-300ms) and causing Google to rate the website “Average” instead of “Good”. When using a CDN, the speed drops even further, causing Google to rate the sites speed “Poor”. Instead of keeping a 100% optimization score, always go for the actual speed. Best tool I can think of for checking the actual speed is Pingdom:
来源:https://stackoverflow.com/questions/37759077/how-to-solve-serve-the-following-static-resources-from-a-domain-that-doesnt-se