unified

Project: rehypejs/rehype-minify

Package: rehype-javascript-to-bottom@2.0.2

  1. Dependencies: 0·Dependents: 0
  2. rehype plugin to move JavaScript <script> to <body>
  1. unified 166
  2. plugin 130
  3. html 109
  4. rehype 73
  5. rehype-plugin 51
  6. minify 30
  7. mangle 30
  8. javascript 13
  9. script 10
  10. js 4
  11. head 3
  12. move 3

rehype-javascript-to-bottom

Build Coverage Downloads Size Sponsors Backers Chat

Move JS <script> elements to the end of <body>.

This can decrease the time to first render.

You can pass filter, a function called with each checked node, returning true if the script should be moved, and false if not.

Install

npm:

npm install rehype-javascript-to-bottom

Use

On the API:

 unified()
   .use(require('rehype-parse'))
+  .use(require('rehype-javascript-to-bottom'))
   .use(require('rehype-stringify'))
   .process('<span>some html</span>', function (err, file) {
     console.error(report(err || file))
     console.log(String(file))
   })

On the CLI:

rehype input.html --use javascript-to-bottom > output.html

Example

In
<!doctype html><html><head><script src="index.js"></script></head><body></body></html>
Out
<!doctype html><html><head></head><body><script src="index.js"></script></body></html>

Contribute

See contributing.md in rehypejs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer