Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to direct parsing of known module content only instead of all served JS #25

Open
usergenic opened this issue Aug 12, 2019 · 0 comments

Comments

@usergenic
Copy link
Collaborator

Right now the middleware, upon encountering .js content, attempts to parse and convert all import specifiers. Apart from being expensive, this is totally unnecessary in cases where delivered .js is not a module (i.e. for regular script tags etc.)

What about this:

  1. When processing HTML content and a <script type=module src="x"> is encountered, rewrite "x" to "../path/to/x.js?__module=true"
  2. When processing HTML content with inline module <script type=module> and import * as x from 'x'; encountered, rewrite "x" to "../path/to/x.js?__module=true"
  3. When process JS content, watch for __module=true query param. If present, remove the query param and forward to proxy, process the returned content and then rewrite specifiers to also include the __module=true query param. (The removal of __module=true query param makes the __module=true bit invisible to the next middleware/proxy in the chain.) Otherwise, do nothing.

This will enable much more performant serving of files which contain a mix of JS types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant