This `rehype` plugin, `rehype-remove-script-type-javascript`, is designed to optimize HTML documents by automatically removing redundant `type` and `language` attributes from `<script>` elements that inherently contain JavaScript. It intelligently identifies and targets scripts with types like `text/javascript` or `language` attributes, leaving module scripts (`type="module"`) and other non-JavaScript script types untouched. The package's current stable version is `4.0.1`. It operates within the `unified` ecosystem, processing `hast` syntax trees. While `rehype-remove-script-type-javascript` has its own versioning, it is part of the `rehype-minify` monorepo, which recently underwent a significant `7.0.0` major release, introducing ecosystem-wide changes such as a strict Node.js 16+ requirement and exclusive ESM distribution. This plugin helps improve page load performance by reducing the byte size of HTML, as these attributes are often unnecessary in modern browsers where JavaScript is the default script type. It offers a focused, declarative approach to HTML optimization within a `unified` pipeline.
npm install rehype-remove-script-type-javascriptVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to integrate `rehype-remove-script-type-javascript` into a `unified` processing pipeline to remove redundant script type attributes from an HTML file.
Upgrade Node.js to version 16 or higher.
Use ES module syntax (e.g., `import rehypeRemoveScriptTypeJavaScript from 'rehype-remove-script-type-javascript';`) and ensure your project is configured for ESM (e.g., `'type': 'module'` in `package.json` or `.mjs` file extension).
Always use `rehype-sanitize` as part of your unified pipeline when processing untrusted or user-generated HTML content.
Update all related `unified` ecosystem packages (e.g., `unified`, `rehype-parse`, `rehype-stringify`) to their latest compatible major versions.
Change `const rehypeRemoveScriptTypeJavaScript = require('rehype-remove-script-type-javascript');` to `import rehypeRemoveScriptTypeJavaScript from 'rehype-remove-script-type-javascript';`. Ensure your Node.js environment supports ESM (e.g., `type: 'module'` in `package.json` or `.mjs` file extension).Ensure your code `await`s the `process` call (e.g., `await unified()...process(...)`). Verify Node.js is v16+ and `unified` package is updated to a compatible version (e.g., v11+).
Add `"type": "module"` to your project's `package.json` or rename the file to have a `.mjs` extension. Ensure Node.js v16+ is used.