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:

  1. Prevent minifying script tags with application/json (this would no longer minify the DrupalSettings, which are already minified anyway.
  2. Allow settings to disable parts of the minification (like JavaScript). More flexible, but harder to configure for users.
  3. 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

CommentFileSizeAuthor
#2 3485673-2.patch991 bytesseanb

Issue fork minifyhtml-3485673

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

seanb created an issue. See original summary.

seanb’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new991 bytes

Changed the regex to skip application/json and application/ld+json script tags.