Add vite_preload_assets template tag for performance optimization
#169
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add new Django template tag to generate tags for Vite-bundled assets, enabling early loading of critical resources like fonts and images to improve page load performance.
assetsfield to ManifestEntry to support asset references in Vite manifestgenerate_preload_assets_tagsmethod inDjangoViteAppClientvite_preload_assetstemplatetag w/file_ext,as_typeand**kwargscrossoriginfor fonts supported via**kwargsmimetypesfrom standard libraryUsage: {% vite_preload_assets 'src/entry.js' file_ext='.woff2' as_type='font' %}
This template tag addresses the performance issue where fonts loaded via CSS
@font-facerules don't start downloading until after the CSS is parsed, causing layout shifts when fonts swap in. For example:You can put this in the
<head>of a base templateWhere
theme/fonts.css.tsis like:Also, the template tag name might cause confusion with the existing
vite_preload_asset(no "s") tag, so maybe I should rename it tovite_preload_linksor something..?Anyways, I hope that extra context helps explain why I'm making this contribution. I've tried my best to follow the repo's existing patterns and included unit tests to maintain the project's high test coverage.
Please let me know if you have any questions or would like me to make any changes.