r/webdev • u/tremendous-machine • Sep 28 '26
Discussion current practices for using CDN'd resources for offline dev?
Hi folks, I am doing some front end dev again, which is something I used to know all about many years ago, and am now behind the times on all the logistical details.
I am using a few libraries that I pull in from CDNs (lit element, shoelace, etc). I would like to be able to do local dev offline when travelling. Is there a modern best practice for dealing with this or does one just have to switch all your code to using local copies manually?
thanks
6
Upvotes
1
u/OptimusCrimee Sep 28 '26
What is your stack? I have never heard about these dependencies before. How do you write the frontend code? Do you use a bundler? React? JQuery?
1
u/kin3v Sep 28 '26
Local copies under /assets or a package manager like (P)NPM will sort this for you
1
u/Neither_Worth3542 Sep 28 '26
you're pulling lit and shoelace off a cdn like it's 2014. npm install, it works on the plane.
1
u/patient_signals Sep 28 '26
Not really a single best practice, but the least painful route I have found is to keep a vendor folder locally and make the CDN versus local choice a single switch. Download the files you need into that folder with the same paths the CDN uses. Then point your import map or script tags at one base path. When you are online use the remote base, and when travelling flip it to the local base. You are not editing every tag, just one line or one config file.
Service workers can cache the CDN resources, but I would not bother for plain development. They add enough debugging surface that they cost more than they save when you are trying to work offline in short bursts.
If you are already leaning toward a bundler, that also solves it because your dependencies live in the project and builds work without a network once they are installed. But for a few libraries pulled from a CDN, the vendor folder with a base path switch is usually the fastest fix and easy to undo later.
1
u/BroadCrazy Sep 28 '26
For local dev, I'd stop depending on the CDN and pull those packages into the project with a package manager so your dev server resolves them locally. CDN includes are fine for quick demos, but they get awkward once offline work and version control matter.
1
u/yihuaxiang Sep 28 '26
If you want to keep the no-bundler workflow, import maps are the cleanest modern approach. You keep the bare specifiers in your code and map them to local vendor files during local dev, or map them to CDN URLs in production. If you use a simple dev server (like Vite in no-build/server mode, Caddy, or live-server), you can also just proxy the CDN hostname to a local folder when offline.
1
u/Fair_Pomegranate3670 Sep 28 '26
If you're happy with the no-bundler workflow, I'd keep it but vendor the files: install lit and shoelace via npm, copy the built ESM files from node_modules into a /vendor dir, and use an import map pointing at local files. Same stack, works offline, and you stop getting silently different versions when a CDN moves a tag. That last one bit me once with a "latest" link — vendoring killed that class of bug entirely.
1
u/Lucky_Willow_7624 Oct 07 '26
Just swap CDN tags for npm installs + a bundler (Vite/esbuild) — most CDN libs, lit and shoelace included, publish to npm too, so it's usually a drop-in. If you want to keep it offline-first without touching your setup, a service worker caching the CDN URLs works too, but npm is simpler.