vite-plugin-html-sort-tags
v0.1.1
Published
Vite plugin for sorting head tags in HTML
Downloads
87
Readme
vite-plugin-html-sort-tags
Vite plugin for sorting head tags in HTML.
Motivation
Handling the order of tags in HTML correctly can sometimes help page performance and user experience. For example,
Vite adds
linktags withmodulepreloadto the end of the head in HTML by default, which can cause preloading to be deferred if head contains other non-async scripts;According to the principle of Browser Resource Hints,
linktags withdns-prefetchandpreconnectshould obviously be added first,preloadsecond, andprefetchthird; and they should all go before resource tags.
The plugin has a default configuration that sorts the tags in the head in what is usually the best order.
This plugin will NOT generate resource hints for you. Refer to vite-plugin-prefetch-chunk and vite-plugin-auto-preload if necessary.
Installation
npm install --save-dev vite-plugin-html-sort-tagsUsage
// vite.config.js
import htmlSortTags from 'vite-plugin-html-sort-tags'
export default {
plugins: [
htmlSortTags(),
],
}Options
order
Type:
(tag: import('node-html-parser').HTMLElement) => numberA function that accepts each tag in head in turn and returns the order number of the tag. Tags with smaller order numbers will be sorted higher.
By default, tags will be ordered in a way that best suits browser parallel loading.
