minify_json_tags

This script will minify JSON-structured script tags in the given HTML file.

<html>
…
  <script type="importmap">
    {
      "imports": {
        "utils": "/j/utils.mjs"
      }
    }
  </script>
  <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "Organization",
      "url": "https://sdavids.de/"
    }
  </script>
…
</html>

<html>
…
<script type="importmap">{"imports":{"utils":"/j/utils.mjs"}}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"Organization","url":"https://sdavids.de/"}</script>
…
</html>

Usage

$ node scripts/web/minify_json_tags.mjs dist/index.html
$ find dist -type f -name '*.html' -exec node scripts/web/minify_json_tags.mjs {} \;

Prerequisites

  • npx

    Afterward, you need to install the dependencies of this script:

    $ npm i --save-dev domutils dom-serializer htmlparser2