News for hackers. Stuff that matters.
Re:Deno 1.9 by tkzed49 on Tuesday April 13, 2021 @05:02PM (#26799265)
How do you actually go about writing isomorphic libraries for browser/deno? It seems like for frontend code you'll have some build system that resolves imports to node_modules, whereas deno code imports from e.g. deno.land. How do you write library code with dependencies that can support that and the other differences in the module systems?
Re:Deno 1.9 by sjy on Tuesday April 13, 2021 @05:11PM (#26799382)
Deno uses ES6 modules, which are supported by modern browsers. There’s no node_modules. https://deno.land/manual/examples/import_export
Re:Deno 1.9 by tkzed49 on Wednesday April 21, 2021 @05:14PM (#26895529)
Yeah, I guess if you don't use typescript? But isn't that a lot of the appeal of deno? The browser can't import a TS module.
Re:Deno 1.9 by sdfhbdf on Tuesday April 13, 2021 @06:01PM (#26799911)
Just like you did in the browsers back in the day when you imported code from URLs with <script src="">, the "deno way" is supposed to follow browsers in these regards as well.

And you can always use `npm`, `node_modules` and `import maps`[0][1][2] to kind of mimic "nodejs way".

[0]: https://wicg.github.io/import-maps/

[1]: https://blog.logrocket.com/es-modules-in-browsers-with-impor...

[2]: https://deno.land/manual/linking_to_external_code/import_map...

Re:Deno 1.9 by coolreader18 on Tuesday April 13, 2021 @05:31PM (#26799597)
Maybe there's a bundler/webpack plugin that supports deno's import system, so it just fetches whatever http urls/analyzes the import maps and turns it into a normal web bundle.
Re:Deno 1.9 by IggleSniggle on Tuesday April 13, 2021 @07:13PM (#26800707)
Deno’s import system is just the ecmascript import system. So, it works exactly the same way it does in the browser. Or with curl. Or whatever. You just supply a uri and get the resource at that location. Things like import maps are just a way to make that more convenient during development, but there’s no secret system for pulling these pieces together; it’s just the ecmascript module standard (that didn’t exist until more recently).
Re:Deno 1.9 by eyelidlessness on Tuesday April 13, 2021 @09:09PM (#26801819)
Yes there are plugins for this in pretty much every build tool and for Node. But they all have a bunch of caveats and mutual discrepancies.
Re:Deno 1.9 by zdragnar on Tuesday April 13, 2021 @05:21PM (#26799491)
Snowpack might be an option
Re:Deno 1.9 by eyelidlessness on Tuesday April 13, 2021 @09:15PM (#26801845)
Their companion CDN (and namesake umbrella parent company) is also a first class part of Snowpack.

However using CDNs in the browser has some big trade offs. Besides obvious concerns sending any data to consolidated third parties, it’s actually a performance detriment now that browsers are caching per origin.

Used to be, using a CDN got you more likely cache hits and better perf on N+1 requests. Now you definitely don’t get that plus you get the extra DNS lookup and whatever performance characteristics of that CDN.

Re:Deno 1.9 by chris_engel on Wednesday April 14, 2021 @02:44AM (#26803756)
There has always been an extra DNS lookup wirh a CDN. Thats even the point of the CDN since based on where you are, you will be served from a location as physically close to you as possible.

Where did you get the information from that CDNs arent as good as they used to be?

Re:Deno 1.9 by richeyryan on Wednesday April 14, 2021 @03:51AM (#26804206)
Safari and Chrome now use a combined cache strategy using the URL of the resource and the top level domain of the site loading that resource as the cache key.

For scenarios that were previously popular like using the jQuery CDN, you won't get the benefit of the user having jQuery in their cache from another website. You will however still get the proximity benefit you describe. CDNs are obviously still quite useful, just not for getting cache hits on popular libraries.

https://www.stefanjudis.com/notes/say-goodbye-to-resource-ca...

Re:Deno 1.9 by chris_engel on Wednesday April 14, 2021 @02:58PM (#26811475)
Yeah thats true - so you explicitly mean CDNs that serve a single thing only.

Using a CDN for your static files is just as fine as it always has been.

Re:Deno 1.9 by eyelidlessness on Wednesday April 14, 2021 @09:27PM (#26815200)
> Where did you get the information from that CDNs arent as good as they used to be?

The other comment addressed this, but to be clear. One of the common usage of external CDN resources is predicated on a performance benefit: if multiple sites use the same resource, it’s more likely to be cached already and much less likely to be impaired by the drawbacks (DNS hit, external network factors). But since browsers have shipped cache partitioning for very good privacy reasons (as other comment mentions, caches are prefixed by the requesting origin), you get no cache benefit and all of the detriment of a clear cache.

Essentially the only reason to use a CDN for third party resources now is if you can bet the CDN will perform better than your local, already DNS-resolved host.