terser / html-minifier-terser

actively maintained fork of html-minifier - minify HTML, CSS and JS code using terser - supports ES6 code
https://terser.org/html-minifier-terser
MIT License
376 stars 30 forks source link

Compress script data block #34

Closed willfarrell closed 2 years ago

willfarrell commented 4 years ago

For google datasets to work it requires Schema.org JSON-LD inline script tag on a page. Compression of this by default or behind a flag would be awesome.

Example

<script type="application/ld+json">
{
        "@context": {
            "@vocab":"https://schema.org/"
        },
        "@type": "Dataset"
}
</script>
DanielRuf commented 4 years ago

Hi @willfarrell,

even if we would add the application/ld+json to the allowed script mimetypes, it would not make a big difference.

image

Because in general this is not valid JavaScript but JSON and this library compresses HTML + JavaScript and CSS. But JSON is not JavaScript.

mauriciabad commented 4 years ago

Terser has an option to parse just an expression:

--parse expression

This may minify the JSON.

DanielRuf commented 4 years ago

Hi @mauriciabad,

I'm not sure how we can add this in html-minifier-terser. This would be a new feature as html-minifier-terser compresses only js, css and html but no other formats afaik.

PRs which add this are very welcome.

DanielRuf commented 4 years ago

This may minify the JSON.

Does it minify it? I'm not sure if this compresses every available form of JSON. Would be good if someone can test and verify this so we can discuss possible solutions.

liuycy commented 2 years ago

{ processScripts: ['application/ld+json'] }

Pass an option like this works for me.