-
Notifications
You must be signed in to change notification settings - Fork 30
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
Minify JSON-LD #146
Comments
Please see #34 (comment) and the other comments there. |
I see, thank you! <script type="application/ld+json"> { "@context": "https://schema.org/", "@type": "MobileApplication", "name": "Fancy App", "description": "Does cool stuff", "applicationCategory": "Entertainment" } </script> |
I gave it a shot, but I can't find any setting that removes the extra whitespace. The example you posted also doesn't remove most of the extra whitespace. It seems that disabling |
Hi there and thanks for this very cool tool :)
It is relatively common for a site to add some form of
json-ld
metadata for search engines or other web crawlers to use. Here is a basic example for a PWA:Currently,
html-minifier-terser
ignores these scripts, which means whitespace is not removed. I would suggest adding a rule calledminifyJSON
that takes any script matching type/^application\/(?:\S*\+)?json$/ui
, and then removes whitespace withJSON.parse()
followed byJSON.stringify()
.If you want to be more advanced, there are also
json-ld
parsers which can theoretically minify the data even more, although I doubt the savings will be very large. For me personally, only removing the whitespace is fine :)The text was updated successfully, but these errors were encountered: