{"id":11928,"library":"rehype-minify-javascript-url","title":"Rehype Minify JavaScript URL","description":"rehype-minify-javascript-url is a rehype plugin designed to optimize HTML documents by minifying `javascript:` URL attributes found within various HTML tags. It's an integral part of the unified collective's rehype ecosystem, which focuses on transforming HTML with a plugin-based architecture. The current stable version is 5.0.1. This package specifically targets and reduces the size of JavaScript code embedded within URL attributes by applying minification techniques (e.g., transforming `alert(true)` to `alert(!0)`). Following the unified ecosystem's release cadence, it ensures compatibility with maintained Node.js versions, currently requiring Node.js 16 or newer. Its primary differentiator is its specialized focus on JavaScript URL minification, contributing to overall HTML document size reduction within the robust rehype processing pipeline.","status":"active","version":"5.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/rehypejs/rehype-minify#main","tags":["javascript","html","mangle","minify","plugin","rehype","rehype-plugin","script","typescript"],"install":[{"cmd":"npm install rehype-minify-javascript-url","lang":"bash","label":"npm"},{"cmd":"yarn add rehype-minify-javascript-url","lang":"bash","label":"yarn"},{"cmd":"pnpm add rehype-minify-javascript-url","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only since version 5 and requires Node.js 16+. It exports only a default function.","wrong":"const rehypeMinifyJavaScriptUrl = require('rehype-minify-javascript-url')","symbol":"rehypeMinifyJavaScriptUrl","correct":"import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'"}],"quickstart":{"code":"import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'\nimport rehypeParse from 'rehype-parse'\nimport rehypeStringify from 'rehype-stringify'\nimport {read} from 'to-vfile'\nimport {unified} from 'unified'\n\nasync function processHtml() {\n  const file = await unified()\n    .use(rehypeParse)\n    .use(rehypeMinifyJavaScriptUrl)\n    .use(rehypeStringify)\n    .process(await read('index.html'))\n\n  console.log(String(file))\n}\n\n// Assuming 'index.html' exists in the current directory with content like:\n// <a href=\"javascript:alert(true)\">Click me</a>\n// For a runnable example, you might create a dummy file:\n// import { write } from 'to-vfile';\n// await write({ path: 'index.html', value: '<a href=\"javascript:alert(true)\">Click me</a>' });\n\nprocessHtml().catch(console.error);","lang":"typescript","description":"Demonstrates how to use rehype-minify-javascript-url within a unified pipeline to parse HTML, minify JavaScript URLs, and then stringify the result."},"warnings":[{"fix":"Migrate your project to use ES modules or update your bundler configuration to handle ESM imports correctly. Use `import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'`.","message":"This package is ESM-only. CommonJS `require()` is no longer supported.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Ensure your development and production environments are running Node.js 16 or a later LTS version.","message":"rehype-minify-javascript-url requires Node.js version 16 or newer.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Always use `rehype-sanitize` in your unified pipeline before or after minification when processing untrusted HTML to ensure the resulting document is safe.","message":"Improper use of rehype plugins, especially when handling user-generated or untrusted HTML, can lead to Cross-Site Scripting (XSS) vulnerabilities.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure you are using a default import, e.g., `import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'`.","message":"The `rehype-minify-javascript-url` package exports only a default function. Attempting to use named imports will result in errors.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Update your import statements to use ES module syntax: `import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'` and ensure your project is configured for ESM.","cause":"Attempting to import an ESM-only package using CommonJS `require()` syntax.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/rehype-minify-javascript-url/index.js from ... not supported."},{"fix":"Verify that you are importing the default export correctly: `import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'`. Do not use `{ rehypeMinifyJavaScriptUrl }`.","cause":"This typically occurs if you try to destructure a named export, but the package only provides a default export, or if the import path is incorrect, leading to an undefined module.","error":"TypeError: rehypeMinifyJavaScriptUrl is not a function"}],"ecosystem":"npm"}