Minify content within script tag of type JSON (importmap, manifest, JSON-LD, etc.)#1157
Minify content within script tag of type JSON (importmap, manifest, JSON-LD, etc.)#1157simonewebdesign wants to merge 3 commits intokangax:gh-pagesfrom
Conversation
| // Try parsing and re-stringifying the JSON | ||
| return JSON.stringify(JSON.parse(text)); | ||
| } | ||
| catch (e) { |
There was a problem hiding this comment.
Is there a way to log the error instead of suppressing it? Similar to what is done here: https://github.com/kangax/html-minifier/blob/ab4c9d6e3e11ab207f545728c918895d5cb4c5f8/src/htmlminifier.js#L740C11-L740C28
| function processScript(text, options, currentAttrs) { | ||
| for (var i = 0, len = currentAttrs.length; i < len; i++) { | ||
| if (currentAttrs[i].name.toLowerCase() === 'type' && | ||
| currentAttrs[i].value === 'application/ld+json') { |
There was a problem hiding this comment.
Import maps (type="importmap") are also often used and should be minified. Could we use an array of acceptable types?
There was a problem hiding this comment.
Great shout! I've implemented that in 25e77e8. It adds support for import maps and makes it much simpler to implement a new format (it will just be a matter of adding it to the array of acceptable types). I've added more types to the list as well, let me know if you think there are any others I've missed!
|
@kangax Really sorry for the ping. Could you please take a look at this PR? Tests are included. |
Resolves #1132, resolves #1152, adds support for import maps and other script tags containing JSON.