As some js files are very common and widely used on the web, why browsers don't reutilise them?
wouldn't it improve efficiency, as js framework files are usually heavy?
As some js files are very common and widely used on the web, why browsers don't reutilise them?
wouldn't it improve efficiency, as js framework files are usually heavy?
They are. If you link to the javascript as hosted by an external source such as ajax.googleapis.com and you have previously got that file while browsing another webpage, your browser will use the cached version (assuming all other cache settings are OK).
Obviously though you are now using google' bandwidth to download that file. Although the overall bandwidth used amongst all websites is less that if each one hosted the same file. Google is paying for more of it.
So you can see that if you are the person hosting the javascript file, you need to be getting some benefit out of it yourself. So for paid products, or advertising stuff where there is value in the metadata of the request for the JS file you do see this happening.
But generally, if you have published a JS framework of some kind, it would cost you money to host the file in a hot linkable way.
One reason is that there is no web of trust in place that would facilitate using code from one source in the rendering of a website from another source. Right now all the code linked in a HTML document is (supposed to) running in a sandbox where it pretty much only access data and functions related to that document and some things about the browser.
What you don't want is that module leftpad from superawesomecompany.com is used widely on the net by various other sites due to its utility, but then it turns out that they secretly phone home all your credentials. If you include the actual code to run in each website, you can at least be sure no sudden changes are snuck in. If you just import leftpad in your code and the code is dynamically loaded at runtime, you can only trust in superawesomecompany and hope they're not evil.
If your site not only depends on your server, but N other servers, you have N additional bottle necks, possible break points, especially if some library becomes popular. Their servers are not necessarily very commercial. They might even blacklist such an abuse of their resources.
Also you do not want to give them statistics and other info on your site.
And hackers then have fruitfull access points for attacks. In the past some PHP frameworks (as PHP was/is popular) had such backdoors.