Skip to content

fix: run replacements function before HTML minification #469

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

Merged
merged 1 commit into from
Sep 21, 2022

Conversation

jackbrewer
Copy link
Contributor

I recently merged a change to add postMessage functionality, inserting it in a <script>, before the closing </body> tag (v3.4.0).

What I didn't notice, is that we run HTML minification before replacements are made, and there was no </body> left to match/replace (it is technically valid HTML to not have a closing </body> and </html>).

This meant the additional <script> is not currently being added. I had been testing against a standalone report which had not gone through the minifier. Previous replacements (now removed) had been working fine, as they were matching against strings which happened to not be changed during the process.

This PR moves the makeReplacements function call to before the minification, with the bonus effect that the replaced code is now also minified.

@jackbrewer jackbrewer requested a review from a team September 21, 2022 16:39
@netlify
Copy link

netlify bot commented Sep 21, 2022

👷 Deploy Preview for plugin-lighthouse processing.

Name Link
🔨 Latest commit 99bfa14
🔍 Latest deploy log https://app.netlify.com/sites/plugin-lighthouse/deploys/632b3e4c86dfbe0008deca10

@jackbrewer jackbrewer merged commit 1e74d86 into main Sep 21, 2022
@jackbrewer jackbrewer deleted the jbr/makeReplacementsBeforeMinification branch September 21, 2022 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants