Imports are loaded twice (with and without cache-busting query string)

Created on 13 January 2025, 10 days ago

Problem/Motivation

When using the feature of this module that adds manifest imports as additional JS files to the Drupal library, the imports are loaded twice by the browser.

Once, by the script tag added with rel = modulepreload, type = module. This one will have the cache-busting string appended, for example:

<script src="/modules/custom/example/dist/assets/vendor-BJeRhW_B.js?spvp1h" rel="modulepreload" type="module"></script>

The second time is when the actual JavaScript module imports the dependency, it doesn't have the cache-busting string.

So the preload doesn't seem to do anything helpful in this case, since to the browser these are two separate assets and the cache can't be used.

Steps to reproduce

Define a vite library that uses imports, but don't create a separate library for those imports. Build for production, clear Drupal caches, and navigate to a page that will render your vite Drupal library.

The expected result is that the import will only be loaded once, but it's preloaded with the cache buster query string then loaded again from the JavaScript module without the cache buster query string.

I will try to put together a failing test case to demonstrate the behaviour.

Proposed resolution

Consider removing the 'preload' script tags since they aren't actually working as a preload, or some other method of reconciling this mismatch.

Remaining tasks

  • Determine correct resolution
  • Write tests

User interface changes

Should be none

API changes

Should be none

Data model changes

Should be none

🐛 Bug report
Status

Active

Version

1.3

Component

Code

Created by

🇨🇦Canada star-szr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024