News for hackers. Stuff that matters.
Re:You may not need Moment.js by armchairhacker on Saturday September 18, 2021 @05:06PM (#28579304)
What's the state of cached ES module imports?

The ultimate goal is, your <script>s are modules, and import their dependencies from a common CDN like unpkg. The browser will cache the import, so that large common imports are rarely actually fetched. Dependencies would have their own cached dependencies as well (although this would sharply decrease efficiency without extra coordination between client / server for bulk fetching).

This would significantly reduce MB-large JavaScript files because most of that code is shared general libraries. Even if you use a huge library like core.js with no tree shaking, it's no longer an issue, as long as many others are also using core.js.

I do know that module scripts can import from remote sites, and unpkg with the experimental '?module' resolves imports in unpkg modules to other unpkg modules. I also know that browsers are very good at caching modules. I doubt browsers are smart enough to bulk fetch multiple unpkg dependencies in one request.

Does anyone have more experience with, in general, trying to cache large JavaScript imports?

Re:You may not need Moment.js by realityking on Saturday September 18, 2021 @05:19PM (#28579409)
> The browser will cache the import, so that large common imports are rarely actually fetched.

Cross site caching is dead. Safari hasn’t supported it in years and Chrome recently dropped it as well. It’s better to hold all assets on your domain to avoid TCP and TLS overhead.

Here’s a blog post with more details about Chrome’s change: https://www.stefanjudis.com/notes/say-goodbye-to-resource-ca...

Re:You may not need Moment.js by extra88 on Saturday September 18, 2021 @05:48PM (#28579653)
Looks like Firefox also made it the default in January with version 85.

https://developer.mozilla.org/en-US/docs/Web/Privacy/State_P...

Re:You may not need Moment.js by doliveira on Saturday September 18, 2021 @05:42PM (#28579591)
Even before the current rules partitioning cache by domain, has the promise of those cached scripts ever paid off? Even when every website would use just jQuery, everyone had a different version, getting it from a different CDN, etc...
Re:You may not need Moment.js by FranksTV on Sunday September 19, 2021 @02:01AM (#28582050)
Look, sometimes we need to tell ourselves stories to make ourselves feel better about the amount of Javascript we're making people download to access our blogs.
Re:You may not need Moment.js by q-rews on Sunday September 19, 2021 @03:34AM (#28582435)
Probably not. A few requests surely got cached, but the vast majority likely did not. jQuery has its own official CDN URL so that probably had a chance at being deduplicated.
Re:You may not need Moment.js by qvq on Saturday September 18, 2021 @05:35PM (#28579537)
> I doubt browsers are smart enough to bulk fetch multiple unpkg dependencies in one request.

https://github.com/WICG/import-maps/issues/209