Problem/Motivation
We currently have a client that has pages that contain lots of data that needs to be pushed to JavaScript. When the minifyhtml module is enabled, this leads to an error when minifying the script tags containing the DrupalSettings.
Backtrack limit exhausted in regular expression "/\s*<script(\b[^>]*?>[\s\S]*?<\/script>)\s*/i" (code: 2).
Steps to reproduce
- Enable the module
- Create a page with a large
DrupalSettings object.
- Observe the
Backtrack limit exhausted in regular expression error.
Proposed resolution
We can do the following things:
- Prevent minifying script tags with application/json (this would no longer minify the
DrupalSettings, which are already minified anyway.
- Allow settings to disable parts of the minification (like JavaScript). More flexible, but harder to configure for users.
- Prevent minifying large strings in general. This would not need any configuration, but risks skipping minifying code that doesn't even cause issues.
Since the module now requires very little configuration, I guess option 1 would be the easiest solution, and still allows minifying other script tags.
Remaining tasks
Write a patch
Review
Commit
User interface changes
None
API changes
None
Data model changes
None
Comments
Comment #2
seanbChanged the regex to skip
application/jsonandapplication/ld+jsonscript tags.