Self-host your static assets (2019)
csswizardry.com
csswizardry.com
> [However] Safari has completely disabled this feature for fear of abuse where privacy is concerned
All major browsers have now disabled shared caches[0][1]. Using a CDN for resources is strictly worse, now, performance-wise.
[0] https://developers.google.com/web/updates/2020/10/http-cache...
[1] https://arstechnica.com/gadgets/2020/12/firefox-v85-will-imp...
It's still normally significantly better if only for the fact the CDN's servers are physically closer to the client.
I should note that I live in Israel, and geograpical distribution by CDNs may be at fault here.
Regardless, as others have noted, I have already connected with the website, third party connections have a high chance if impacting perfotmance for the worse.
The permutations of different CDNs and asset versions meant the cache hit rate was low anyway.[1][2]
[0] https://www.cs.umd.edu/~jkatz/TEACHING/comp_sec_F04/download... (PDF)
[1] https://zoompf.com/blog/2010/01/should-you-use-javascript-li...
[2] https://web.archive.org/web/20111123170325/http://statichtml...
A CDN with DCs in a number of locations and appropriate DNS setup at least has the advantage of local delivery which can have more than zero significance if you have an international audience and you really need low latency.
But if you are in that category then you probably won't (or shouldn't) be loading a bunch of stuff from a CDN or otherwise. And I wouldn't source script from a 3rd party anyway, I never saw the security tradeoff as worth it.
Doesn't subresource integrity [1], i.e. specifying the expected hash of the script, solve those security issues? Unless you need to support Internet Explorer, I suppose.
[1] https://developer.mozilla.org/en-US/docs/Web/Security/Subres...
Though for personal projects I'll stick with self-hosting, and in DayJob we unfortunately still have to support IE11 to an extent (and beyond that some of our clients strictly whitelist everything and will reject a 3rd party they can't fully audit, ruling out CDNs for those at least, every with SRI).
I manage a normal looking regional news site. First load is 691KB. Megabytes don't come into it.
(I cheat by not having Google Ads on the page, but lol, Google is the one who sucks. Our house ads are fine.)
Firstly, once you've visited the site personally, the assets will be cached for you anyway. Assuming the site updates its CDN'd assets once a month, the shared cache might possibly save you the first hit each month if you've visited another site that uses the same exact assets beforehand. (But given that the asset has just been updated, this seems unlikely.) So we're not talking about two hits a day.
Secondly, the vast majority of the site will not be on shared CDNs, because it's specific to that site. Images are usually the biggest offender in terms of page load, and those are very unlikely to end up in a shared cache. In a busy marketplace like that of news media, brand identity is very important, so I would guess that most of the CSS is either custom or customised, and therefore not in a shared cache. I don't know how much JS the site uses, but I'll be generous to your argument and assume they use jQuery, which is hosted on a shared CDN. Custom JS is obviously not used on other sites, so won't be in the shared cache.
And thirdly, there's a reasonably high chance, even if the jQuery stuff is hosted on a shared CDN and you've visited another page that uses jQuery before, that either the CDN host is different, or the version of jQuery being downloaded is different. It's unlikely that everyone updates immediately when a new version is released, which leaves you with a long tail of different versions being spread out over different hosts.
A better estimate probably like like this:
* Assume only one hit per month - the rest would have been cached anyway after the first visit to the site. * Assume only a minified version of jQuery is hosted via a shared CDN. * Assume that half the time, the version of jQuery used on this particular site is so unique that it wouldn't have been found in the shared cache.
According to Bundlephobia, the gzipped, minified size of the latest jQuery package is about 30kB. Assuming we would have had to download it anyway on about 50% of requests, and given that every request after the first would is cached anyway, you're saving around 15kB a month on average.
Assuming 3GB data a month (based on your 1% figure), that's about 0.0005% of your data each morning getting a successful cache hit that it would not otherwise have got if the shared cache was not there.
Google claims a 4% increase in bytes over the network.
What kind of pages are we talking? Print-ready image archives?
If web designers don't care, at least the browser can try to clean up the mess.
I think it's ironic that we thrash chipmakers for side channel attacks that realistically couldn't ever be exploited but the same people turn around and call 14 different scripts from 14 different domains to display a 900kb web page.
Who really knows who has access to or is tracking access to that code? And what happens when one of them goes down?
"The CDN is WAY more reliable than my server."
But your server is the least common denominator. Who cares if your scripts load if your server doesn't? For low volume, unless you have redundancy at every level of the stack; you can't get more reliable than one box.
You may be right 99.9% of the time. But if your site starts being used by someone automatically testing stolen credit card to see if they work you will be thankful for the automated script detection this gives. Every chargeback cost the vendor $20, now imagine 1k of those in a sort period of time, not pretty.
So far I have fortunately not been a victim of this but have read about people who have and it gives me enough fear to stick that script on all pages.
Also friction in the checkout process is bad and can contribute to dropouts. You can decide to always enforce 3d secure or to have it only run when banks require/suggest it. Personally I set a cart total threshold above which it’s required and set it only to be applied when banks require it for lower value orders.
Obviously you can't reasonably "roll your own" payment provider, but that doesn't mean I need to run their code with my name at the top of the page.
The main use of this is to detect automated scripts running cards on your site to test if they work.
Obviously it’s an endless battle as the fraudsters move to using tools such as puppeteer/playwright to simulate a human using a browser.
The old way of having your server rendered pages on your main domain and static assets on static.domain.com really should end. Less of an issue if your doing jamstack with no server side rendering or using something like Vercel.
This is also one of the advantages of using a combined waf/cdn such as CloudFlare. It allows you to have everything on the same domain while also having the use of waf and cdn capabilities. There is no need to have a subdomain to hold your static assets if you want to place it behind a cdn service. The only potentially problem is if your main hosting provider or tech stack makes having everything on one domain difficult.
I mostly work with Python on the sever and have found “whitenoise” a great way to achieve this.
Obviously it’s still easer to host any “dynamic” assets or user submitted assets on a subdomain. (There are good arguments that user submitted assets should be on another domain completely for belts and braces security)
This is no longer true. Due to security concerns browsers no longer re-use the cache between websites.
That said, hosting assets yourself is fantastic if you use a CDN. Accessing American websites without CDN from Europe can be quite rough. I remember one of my first remote freelancing gigs where it took about 5s to load the company’s website hosted on Heroku. Just because of availability zones.
At my current gig, we self-host our assets and it’s fine because we’re US-centric. We host in us-west-2 and I live in SF and everything loads super fast. But you can really tell the dev site loads slower when working from the east coast.
Network latency is no joke.
My development is faster than ever, my web pages are faster than ever, and I can spend more time making sure the website delivers information effectively than worrying about gluing a million disparate frameworks together.
In the web3 space, all the “call to actions” are direct payments, so the funnel is reduced to a single step - optimized by orders of magnitude over the long winded funnels of web 2.0 services for even higher margins and even faster sales cycles
most of the learnings from all these other frameworks was to optimize for the most user experiences to keep them engaged for a convoluted product where the user session needs to be transferred between views and made longer and longer
In a world where most sites and services never needed to do that, and the current web3 ones that monetize well definitely don't need to, none of this complicated frontend (or associated backend) matters any more
The only remaining relevant learnings from the past 10 years are responsive design for different screen sizes, CDNs for even more caching, and better auto deployments from version control updates
1. Is it hosting on our own CDN endpoints. How easy to set this up? Is there a 0 cost way of doing it for our experiments?
2. Alternatively hosting them on our own github pages or repos? - here we still depend on GitHub CDN.
You can (should, as he says at the end) have this be through a CDN. Just use the same CDN you use for other stuff.
Even if HTTP/2 is faster to load multiple assets over the same connection, I found it still better for users on other continents to serve my web app over the main domain from my server in US-East or Central and have a global CDN catching ALL my assets (not 5 CDNs for 5 different JS frameworks)
It's not so much you need JQuery version x cached from another origin, but once its loaded from your site, it never needs to be sent again. Heck you cache everything, or everything except index.html if you want to.
Another aspect to this is if the user blocks Javascript from various third-party domains, your stuff doesn't execute.
If I have 100kb of content that needs 500kb of JS... I lose a lot of bandwidth if I were to self host.
1. It can, but - be kind to your site visitors and don't use such bloat.
2. The article said that if this the bandwidth really an issue for you, then you might as well put your entire site on a CDN and be done with it.