jspm / generator

JSPM Import Map Generator
Apache License 2.0
160 stars 20 forks source link

Querystring support #278

Open guybedford opened 1 year ago

guybedford commented 1 year ago

For cache invalidations, a common pattern is to add query strings - ?q=asdfhjkl with a random timestamp or hash.

When using the generator, we could enable an option to include "querystrings" in the map, something like the following:

new Generator({
  querystring: 'q=asdfjkll'
});

await generator.install('pkg');

// includes "pkg": "/path/to/pkg?q=asdfjkl"
// ALSO includes "/path/to/pkg/dep.js": "path/to/pkg/dep.js?q=asdfjkl" for non-mapped deps!
console.log(generator.getMap());
guybedford commented 1 year ago

Ideally one would want to scope the querystring stuff to specific domains / parents though. Eg you likely don't want it for the JSPM CDN, just the local package code... not sure how best to define that part.

guybedford commented 7 months ago

Perhaps querystrings is an object configuration:

type QueryStrings: Record<String, String>

where

new Generator({
  queryStrings: {
    '/': 'timestamp=asdf',
    'https://esm.sh/': 'dev'
  }
});

Then when processing URLs we would always strip all querystrings, but then add them back at the very end of the import map construction process as a post-processing of the import map, possibly even after the import map has been serialized into JSON. like a const map = importMap.getMap(); const mapWithQueryStrings = postProcess(map) step.