Skip to content

assets: PreloadHTML emits inert links for generic recognized resources #251

Description

@linkdata

Problem

assets.PreloadHTML promises to load resources efficiently and says recognized non-JavaScript/CSS resources are emitted as preload tags. For generic recognized MIME types it emits rel="preload" and type, but no as destination:

html, _ := assets.PreloadHTML(&url.URL{Path: "module.wasm"})
fmt.Print(html)

Output:

<link rel="preload" href="module.wasm" type="application/wasm">

The HTML preload algorithm derives its request destination from as and stops when the destination is absent or invalid. The type attribute does not replace it, so this tag does not perform the promised preload.

This is an optimization failure only: it does not prevent application code from fetching or instantiating the WASM separately.

Proposed fix

Do not emit destination-less preload links. For application/wasm intended for fetch, emit as="fetch" with matching CORS/credentials metadata, normally crossorigin. Map other supported MIME types to valid destinations, or narrow the documented supported resource classes when their consumer cannot be inferred.

Acceptance criteria

  • A MIME-recognized WASM URL produces an effective as="fetch" preload with matching CORS mode, or is explicitly outside a narrowed documented domain.
  • No supported recognized resource is emitted as a destination-less preload.
  • Tests use a process-local registered MIME extension where needed to remain platform-independent.
  • Existing JavaScript, CSS, image, font, favicon, and URL-escaping behavior remains covered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggoPull requests that update go codeseverity:low

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions