Member-only story
🍎 The Reason Why Some Big Websites Store Javascript In HTML
For years i was working as a performance oriented web app developer. So i can answer this question pretty well.
So what we need to take into account is how website or web app is built. It consists of a structure (html) of a document, styling of the document (css) and instructions (js).
JS tells the browser what to do and when so that web app will become interactive.
JS can be embedded inside HTML or be loaded as a separate resource.
Up until some years go browsers had a difficulty to load separate resources. One of the reasons was that browsers were single threaded. So loading one resource was possible with a delay from loading the previous one.
So it was a trend to put JS reasonably into HTML to load it at once.
But things changed. Browsers become multiprocess ones and they handle multiple resources pretty well. So natural it would be to load them separately. Because you can pack the same stuff that never changes into one JS and tell everyone to store a copy, so it wont be loaded again. And web app is faster. But its not everything in case of loading JS to take into account.
One thing is that huge websites have millions of users. Each user makes a call to website often. So the difference…