Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress script data block #34

Closed
willfarrell opened this issue Mar 3, 2020 · 5 comments
Closed

Compress script data block #34

willfarrell opened this issue Mar 3, 2020 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@willfarrell
Copy link
Contributor

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
Copy link
Contributor

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
Copy link

Terser has an option to parse just an expression:

--parse expression

This may minify the JSON.

@DanielRuf
Copy link
Contributor

DanielRuf commented Apr 15, 2020

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 DanielRuf added the help wanted Extra attention is needed label Apr 15, 2020
@DanielRuf
Copy link
Contributor

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
Copy link

liuycy commented Mar 19, 2022

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

Pass an option like this works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants