renatomarinho / laravel-page-speed

Package to optimize your site automatically which results in a 35%+ optimization
MIT License
2.4k stars 275 forks source link

🐞 Bug `RemoveComments` + `CollapseWhitespace` - Correctly handle `//` JS comments #188

Open Rikj000 opened 6 months ago

Rikj000 commented 6 months ago

Detailed description

Currently the RemoveComments,
and thus also CollapseWhitespace middlewares don't correctly strip out // Comments from JavaScript <script> tags.

Context

The described issue leads to broken compressed pages due to JavaScript code being // Commented out.

This also leads to confusion with developers trying to implement this package,
some might abandon the package, thinking it is broken while it is not.

Work Around

Replace all your JavaScript // Comments with <!-- Comment -->s

Your environment

Software Version
PHP v8.1.27
Laravel v10.43.0
Laravel-Page-Speed dev-master https://github.com/renatomarinho/laravel-page-speed/commit/b16c0185ae6816b47c8534b4ecfbce73e6c11cf8