question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unpkg CDN as a fallback?

See original GitHub issue

Hi @lukejacksonn, first off, thank you so much for putting this together.

While using servor for my prototype work, I wanted an ability to use servor without even npm installing my dependencies 🎉 🎉

One way I was thinking to solve this, is by adding a check in servor to see if we are serving a JS file. If a JS file is not available locally, we rewrite the URL to UNPKG CDN URL.

For Example:

Let’s say I have code like this in say index.js:

import { patch, h } from 'superfine';
import store from '@vanillajs/store';

servor would rewrite this to something like this (when node_modules is not available):

import { patch, h } from 'https://unpkg.com/superfine@6.0.1?type=module';
import store from 'https://unpkg.com/@vanillajs/store@0.1.7?type=module';

To take it a step further, if I do not have package.json, we simply rewrite the URL to something like this:

import { patch, h } from 'https://unpkg.com/superfine?type=module';
import store from 'https://unpkg.com/@vanillajs/store?type=module';

This idea has been explored before with owc-dev-server and works quite well using express-transform-bare-module-specifiers

However, I would like a no-dependency solution for this to be available in servor

thoughts/concerns?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
osdevisnotcommented, Apr 17, 2019

Awesome, I’ll try to get to this soon. We will need to explore if this can bring any unforeseen hurdles if we make it a default. Alternative would be to have a flag to disable this behavior.

0reactions
lukejacksonncommented, Apr 27, 2019

Hey @osdevisnot if you figure this out then please open a PR and reference this issue. I’m very interested in what it might look like but am doing a tidy up here so am going to close for now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

UNPKG
The CDN for everything on npm. ... (i.e. use a “bare” URL), unpkg will serve the file specified by the unpkg field in...
Read more >
How to add fallback for a failing CDN - Stack Overflow
My original solution was to check if CDN has failed, and if so use document.write to insert the fallback <script> into the DOM...
Read more >
FALLBACK 1.0.0 CDN links [jden/fallback] - CDNPKG .com
1 CDN to use with FALLBACK (jden/fallback) 1.0.0. Find out the best CDN to use with fallback 1.0.0 or use multiple CDN as...
Read more >
January 2017 – Scott Sauber
asp-fallback-src="https://unpkg.com/promise-polyfill@6.0.2">. </script> ... The built-in Script Tag Helper – CDN fallback.
Read more >
dotnet-unpkg - Discover .NET
Pure .NET front-end HTML package management using unpkg.com as a source. ... There's a magic CDN called unpkg.com that delivers files from NPM...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found