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

Remove VERSION from libraries.yml #408

Open
millnut opened this issue Jan 23, 2025 · 7 comments · May be fixed by #411
Open

Remove VERSION from libraries.yml #408

millnut opened this issue Jan 23, 2025 · 7 comments · May be fixed by #411
Labels
good first issue Good for newcomers

Comments

@millnut
Copy link
Member

millnut commented Jan 23, 2025

The version: VERSION lines in libraries.yml create a version query string using the Drupal Core version number for the asset files. This causes the files to be cached in the browser and will only invalidate when the core version changes due to the dependency on the version.

<script src="/modules/contrib/localgov_alert_banner/js/alert_banner.js?v=10.4.1"></script>

When using edge caching or CDN caching this makes it difficult to invalidate the cache if there are changes to these assets and it requires users to manually clear their browser cache to get updated asset files.

By removing the VERSION Drupal will generate a hash id to the file which can be invalidated and new hash IDs generated when the Drupal cache is cleared e.g. drush cr

The string changes on every update or full cache flush, forcing browsers to load a new copy of the files as the URL changed.

See: web/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php:62

Examples with no VERSION set showing changes based on cache clears;

<script src="/modules/contrib/localgov_alert_banner/js/alert_banner.js?sqjnfy"></script>

<script src="/modules/contrib/localgov_alert_banner/js/alert_banner.js?sqjnm9"></script>
@andybroomfield
Copy link
Contributor

If this is the standard other module implement, and if it is causing an issue we remove it.

Interesting though I'm seeing the hash being added.

Image

@millnut
Copy link
Member Author

millnut commented Jan 23, 2025

Interesting @andybroomfield I don't seem to get the hash as well as the version number. I'm using 10.4.1 at the moment.

I also noticed a few modules which seem to be removing VERSION

@andybroomfield
Copy link
Contributor

@millnut As most sites will use css and js aggregation, this issue wouldn't occur for those sites?

@millnut
Copy link
Member Author

millnut commented Jan 23, 2025

Let me check that @andybroomfield just incase Drupal does anything unexpected as part of the aggregation, I know recently there have been a lot of changes in and around the aggregation of js/css

@andybroomfield
Copy link
Contributor

Quick check in my near default LGD install shows 218 results in 67 files for version: VERSION.

Has there been a change in the recommendation recently? It seems the done thing is to add it.

Image

@andybroomfield
Copy link
Contributor

andybroomfield commented Jan 23, 2025

Searching led me to this article which explains the version key and a Drupal issue that this is not available to contrib modules.

So I agree, we should remove it even if it is standard to use it because:

  • It doesn't use the module version number, but the Drupal Core version number
  • We won't have an automatically generated version number until we move this module to Drupal.org for packaging.

Subject to checks that this does not effect css and js aggregation (I don't think it should).

We should do the same in any other LGD module.

@millnut
Copy link
Member Author

millnut commented Jan 23, 2025

Thanks for finding that issue @andybroomfield I was searching for that in my history/bookmarks but couldn't find it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
2 participants