6 ms·
Revisiting the “Cookieless Domain” Recommendation
- ernestipark 12y agoGreat post by Jonathan. For the case of a big 'single page' JS app where a most of the rendering happens from Javascript fetched on the page, I'd guess this approach won't help that much since you have to fetch the JS from the CDN/cookieless domain anyways. Still though, definitely worth an experiment to know for sure.
- morgante 12y ago> For the case of a big 'single page' JS app where a most of the rendering happens from Javascript fetched on the page, I'd guess this approach won't help that much since you have to fetch the JS from the CDN/cookieless domain anyways. If you're taking that approach, you probably don't care much about performance anyways (I've never seen a pure JS SPA which rendered fast).
- colanderman 12y agoFastMail begs to differ: http://blog.fastmail.com/2014/12/15/dec-15-putting-the-fast-in-fastmail-loading-your-mailbox-quickly/ http://blog.fastmail.com/2014/12/15/dec-15-putting-the-fast-... Loads & renders in between 0.5-1.0s. (Though I must say FastMail is rather unique in this regard.)
- kuschku 12y agoReminds me of the time, 2 or 3 years ago, when Google announced that every page which would take more than 300ms to load and render would be downranked in the search. Seems like we’re going backwards...
- thekingshorses 12y agotry http://hn.premii.com/ http://hn.premii.com/ - Even though it relies on 3rd party for data (backend), it loads quickly. If you have a control over backend, you can optimize it further.
- leeoniya 12y agoi'm personally fairly irked about the massive shift towards "cdn all the things!", i have noscript blocking third-party assets and a larger number of sites is broken for me every day. rather than cdns, there should be an sha or md5 hash sent with every asset, like an etag, so that things need not live on a specific domain to be pulled from cache. EDIT: those downvoting, care to state your case?
- TazeTSchnitzel 12y agoI've wanted something like that. The main problem is security: find a hash collision, magic XSS.
- leeoniya 12y agothough you could say this about any system that uses hashing. if sha256 or 512 is used, the likelihood of collisions with other functioning code, especially code that would yield useful xss seems impossibly small.
- moe 12y agoBetter yet, use multiple hashes. Finding a simultaneous collision in sha256 and md5 seems pretty unlikely.
- lmm 12y agoNo. This is bad advice, do not do this; it comes up every time there's a problem with a hash algorithm. The equivalent number of bits in a hashing algorithm designed as such (e.g. sha-384) will be substantially more secure than sha256+md5.
- moe 12y agoThat's not the point. The point is that you don't want to stand on only one leg when a flaw in that leg may be discovered in the future. Admittedly MD5 was a poor example from me in that light... A more realistic mix might be: sha256+RIPEMD160+Whirlpool. Or, in crypto-speak: Concatenating outputs from multiple hash functions provides collision resistance as good as the strongest of the algorithms included in the concatenated result. [1] [1] http://en.wikipedia.org/wiki/Cryptographic_hash_function#Concatenation_of_cryptographic_hash_functions http://en.wikipedia.org/wiki/Cryptographic_hash_function#Con...
- joevandyk 12y agoIf you terminate SSL at the CDN, if you don't own the network and CDN, won't that leave your data open while in-transit between the CDN and the app servers? I'm using cloudfront and aws, reluctant to let cloudfront be the root CDN because of this. Anyone got any insight?
- rb2k_ 12y agoIs there a reason your CDN couldn't talk to your backend via SSL too?
- deleted 12y ago[deleted]
- firloop 12y agoCan't speak for Cloudfront, but I do know that Cloudflare has mitigated this problem. When you set up SSL, you have the option to force SSL from end to end. Of course, this approach means that SSL is terminated twice, once at the CDN and again when the user receives it, and this also relies on the assumption that you can trust Cloudflare with your data as it passes through their internal network.
- iancarroll 12y agoCloudFront can do this easily: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/SecureConnections.html http://docs.aws.amazon.com/AmazonCloudFront/latest/Developer...
- brianpgordon 12y ago> Here’s the rub: when you put CSS (a static resource) on a cookieless domain, you incur an additional DNS lookup and TCP connection before you start downloading it. Even worse, if your site is served over HTTPS you spend another 1-2 round trips on TLS negotiation Unless you're using SPDY, using a different domain doesn't add any more TLS overhead than using the same domain, right? I didn't think that browsers reuse connections to the same server.
- TazeTSchnitzel 12y ago>Unless you're using SPDY, using a different domain doesn't add any more TLS overhead than using the same domain, right? I didn't think that browsers reuse connections to the same server. This isn't new to SPDY: HTTP/1.1 has keep-alive.
- brianpgordon 12y agoYou're right, I was confusing keep-alive with pipelining, which browsers typically don't support.
- imaginenore 12y agoWhat do you guys think of having the absolute minimum page with inlined everything (even images) that just shows a simple progress bar - it loads the rest of CSS/JS/whatever. I've done it once for a large front end app, and it worked pretty well - the user gets an almost instant webpage and sees that the stuff is loading.
- uaygsfdbzf 12y agoYou are duplicating the 'loading' indicators in the browser.
- hayksaakian 12y agoIt helps mobile users determine if their connection is simply slow or completely timed out. If I don't see even a loading screen, I assume my connection is bad and reload, instead of giving it a bunch of time to load absolutely everything.
- bbcbasic 12y agoOnly works if you can play tetris while you wait
- ajasmin 12y agoGmail greats us with a loading indicator like that.
- kansface 12y agoI would greatly prefer you make websites that don't require progress bars.
- dspillett 12y agoBrowser progress bars are hardly reliable though. IE's can get to ~80% before a single byte is received.
- iopq 12y agoI'd prefer if it had text I could read while I'm waiting for your 1000x1000 background image to load.
- deleted 12y ago[deleted]
- elchief 12y agoOne issue is that you should not use any compression (http or tls) on a request/response with any sensitive info, such as session ids or csrf tokens (see beast, crime attacks). It's easy to turn off compression on your www domain and turn it on on your cdn domain. So now you're not compressing your css, which would slow the response time, but by how much I can't say. You could still use css minification.
- bluesmoon 12y agoyou're confusing content compression with header compression. it's fine to pre-gzip your css before serving it over http or tls.
- elchief 12y agoHTTP compression is simply not safe on your main web domain: http://security.stackexchange.com/questions/20406/is-http-compression-safe http://security.stackexchange.com/questions/20406/is-http-co... What I was trying to say is that, if you're security conscious, and running a CDN anyway, it might not be worth the risk to allow (selective) HTTP compression on your main web domain. It would be safer to disable it completely.
- gingerlime 12y agoPerhaps a silly idea / question, but could browsers support some kind of an optimization meta tag that tells to fetch the resource without sending cookies? something like `<img src="..." data-no-cookies=true>` or even a directive that applies to all static resources unless specified otherwise, e.g. `<meta no-cookies-for="jpg;css;js">` ??
- bodyfour 12y agoIn HTTP/2 (SPDY) the only headers that need to be sent are ones that changed since the last request on the connection. So once that is more common you'll actually be better off just attaching the cookies to all requests since that will mean they only get sent once per TCP connection.
- tracker1 12y agoI've been suggesting a move towards HTTPS only (for security) with SPDY/HTTP2 support.. for my own usage, 2/3 of the clients support SPDY... so having more resources from the initial domain is a better win.. with PUSH resources for CSS/JS with initial connection it gets better still. If ES6 (including modules) were supported in browser, it would be pretty awesome as an addition to SPDY... I think we're reasonably 5-6 years off before any broadly available sites can really use it, but it's cool. Similar compared to Web Sockets a few years back. Given that a lot of interactive data is now pushed to dedicated API services, and images are offloaded for CDN, it's far easier to deliver CSS and JS with the markup on the same deployment(s).
- paulsutter 12y agoSeparate domains for CSS and images files are primarily intended to overcome certain (old?) browsers' limitation on the number of concurrent connections to a single domain [1][2]. Cookieless domains can only help you if you have supermassive cookies. Keep those to a special subdomain, if you really need to have them. But you probably don't. There is no one rule of thumb for performance. Generally, inline everything that's small enough to inline. If it's big enough such that caching a separate file will help you on subsequent page loads, then put it in a separate file. Test and measure. If you can't measure the difference, it doesn't matter. If you don't measure the difference, the rule you are following probably isn't helping you. [1] http://www.stevesouders.com/blog/2013/09/05/domain-sharding-revisited/ http://www.stevesouders.com/blog/2013/09/05/domain-sharding-... [2] http://www.stevesouders.com/blog/2008/03/20/roundup-on-parallel-connections/ http://www.stevesouders.com/blog/2008/03/20/roundup-on-paral...
- gry 12y ago> Test and measure. If you can't measure the difference, it doesn't matter. If you don't measure the difference, the rule you are following probably isn't helping you. /Yes/.
- sgustard 12y agoThat's a sad state of affairs for our industry, though. It's like every structural engineer being told to measure which is stronger, iron or steel. How about some basic shared knowledge we can all trust and build on?
- ChuckMcM 12y agoThere may yet come a day when all steel is sold by weight, manufactured in unnamed factories at unknown chemical compositions such that the only way to know if a piece of steel you have will carry the weight being asked of it, is to use a sample of it in a test fixture. Unfortunately that day is already today on the Internet, where browsers have unknown design decisions made of unknown reasoning across networks that were optimized for unknown requirements.
- gojomo 12y agoI don't trust this analysis. There's no clear mechanism for why forcing the CSS to the same domain would speed things up. Also, the comparison doesn't truly isolate the same-domain/different-domain decision as the cause of any slowdown. Perhaps, the test server is simply less-loaded/less-laggy/network-closer to his measurement browser... so it's the move fo the CSS to that server, not the unification of source domains, that causes the measured speedup. Or many other things.
- youngtaff 12y agoLoading CSS from the same domain speeds things up for a couple of reasons: 1. No DNS look up for the second host 2. Many browsers speculatively open a second TCP connection to the original host in anticipation that another request will be made so the TCP negotiation overhead for the second request moves forward 3. CSS is on the critical path for rendering so getting it more quickly improves rendering time
- gavinpc 12y agoIs the "flash of unstyled content" really so "dreaded"? I've noticed it regularly on the publish side of the Google Play Store. The chain reaction this sets off in my head is about 100 FUOC's long. And it goes something like this. Hey, I just saw a FUOC on the Google Play store admin! They must not be optimizing CSS delivery for above-the-fold content... [0] Or maybe they just don't lavish the same resources on admin sites as they do on front-end... I mean, did anyone else see that? And what if they did? What would they think? They wouldn't think anything, because only a web developer would even recognize a FOUC... And even if someone else saw it and recognized it for what it was... so what? If I tried to explain to someone what happened in that moment, that Google, yes, Google had failed to expend all the necessary brain power on ensuring that their markup was not rendered a fraction of a second before their stylesheets were parsed... And that people actually care about that, actually want to protect users from that horrid sight... I would be seen for what I am, which is a madman. [0] https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery https://developers.google.com/speed/docs/insights/OptimizeCS...
- lucaspiller 12y agoI use a lot of high latency connections (my country has rather slow ping times to major internet centres - around 200ms) and sometimes connections just get "stuck" when loading the CSS. This results in seeing the title of the page with a loading spinner and a blank white page. If browsers actually rendered the page (is CSS really that important on a news site?) I would at least be able to see the content.
- leviathan 12y agoI have the same problem with my internet. So many times have I given up waiting and just hit cmd+u to view page source and read the info I want in raw html.
- nothrabannosir 12y agoParanoia over the FOUC is the bane of my web browsing days. Any time you use unstable internet (hostels in poor countries), designers' prude paranoia over their naked content being shown without the proper styling or font, it ruins modern web browsing. I stopped timing when every other page I saw was literally > 1 minute of waiting. Started using view-source: to just read the damn content. Please, for the love of God, stop hiding content behind styles. Please. Please please please.
- seriocomic 12y agoI've always shirked away from a separate "cookie-less domain" in favor of cookie-less sub-domains (think costs and SSL). This does require you to think about www/no-www (cookie-less sub-domains require you to limit the cookies to the www sub-domain, as no-www means that *.domain inherit all cookies). I wonder if this is still relevant in the HTTP2/SPDY world?
- giantLinux 12y agoSince ETags are optional in the HTTP-1.1 spec, I think we should all just be able to turn them off in our browser. But I can't find an about:config setting in Firefox to do it. WTF, Moz people? Fixing the protocol itself seems possible, too. Have the client side compute a hash of the image (once, upon first retrieval of the image) and cache that with the image. The hash algorithm will be specified in the protocol. Then when the client side wants to know if the image has changed, it sends the hash that it computed. No choice on the server's part, no ability to make the client store an ETag full of arbitrary data. (Yes, malicious servers could perturb their images for every HTTP connection, and precompute the hash, and then store that hash so when the browser came back later, the server could id the browser from the perturbed image hash the client sent. But at least this would require running an expensive hash function for every connection. For that matter, cut out the middle-man. Any server that uses dynamically generated HTML can embed a 1x1 transparent GIF in the page, the URL to which is uniquely generated URL. Then any GET request on that uniquely generated URL would identify the browser. But a cache clear would solve both of those, so at least we'd have a counter-measure...)
- vkjv 12y agoI think a much more interesting concept is prefetching files. Load the link to content with some of the critical files it needs to download, so that the browser can start downloading them before resolving the link. https://developer.mozilla.org/en-US/docs/Web/HTTP/Link_prefetching_FAQ https://developer.mozilla.org/en-US/docs/Web/HTTP/Link_prefe...