Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

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

@usergenic

Description

@usergenic

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions