Skip to content

Release v3.1.0 - Critical Bug Fixes & Enhanced Robustness

Choose a tag to compare

@renatomarinho renatomarinho released this 24 Oct 21:39
· 23 commits to master since this release
4fedf5a

Release v3.1.0 - Critical Bug Fixes & Enhanced Robustness

This release includes critical bug fixes and significantly improved test coverage to ensure package stability and reliability.

🐛 Critical Bug Fixes

1. JavaScript Comment Removal Bug (#180, #184)

Issue: The RemoveComments middleware was incorrectly removing // characters inside JavaScript strings, breaking code:

var url = "http://example.com"; // Comment
// After processing: var url = "http:"; ❌

Fix:

  • ✅ Complete refactoring with character-by-character parser
  • ✅ Proper string state tracking (single quotes, double quotes, regex literals)
  • ✅ URL preservation (http://, https://, ://)
  • ✅ Line ending preservation for cross-platform compatibility

Tests: 8 new comprehensive tests covering edge cases

Fixes: #180, #184


2. InsertDNSPrefetch Extracting URLs from JSON-LD (#179)

Issue: The InsertDNSPrefetch middleware was incorrectly extracting URLs from:

  • JSON-LD structured data (<script type="application/ld+json">)
  • JavaScript code inside <script> tags
  • CSS code inside <style> tags

This caused unwanted DNS prefetch tags and SEO issues.

Fix:

  • ✅ Refactored to extract URLs ONLY from HTML resource attributes
  • ✅ Supports: <script src>, <link href>, <img src>, <a href>, <iframe src>, <video>, <audio>, <source>
  • ✅ Ignores: Script content, style content, JSON-LD, inline JavaScript

Tests: 3 new tests for JSON-LD, JavaScript, and edge cases

Fixes: #179


3. PCRE Error Handling for Large HTML

Issue: Large HTML documents could exceed PCRE backtrack/recursion limits, causing blank pages.

Fix:

  • ✅ Added PCRE error detection in PageSpeed::replace()
  • ✅ Graceful fallback to original content on PCRE errors
  • ✅ Prevents blank pages

Tests: 2 tests with 5,000 and 20,000 line HTML documents

Related: #184


📚 Documentation & Test Coverage

DeferJavascript Comprehensive Test Suite (#173)

Added: 17 extremely robust tests (47 assertions) documenting all edge cases:

Basic Functionality:

  • Adds defer to external scripts
  • Preserves existing defer attributes
  • Respects data-pagespeed-no-defer
  • Does NOT modify inline scripts

Edge Cases:

  • Type attributes (text/javascript, module, application/ld+json)
  • Async attribute
  • Integrity and crossorigin attributes
  • Multiple scripts with mixed configurations
  • Empty src attributes
  • Relative/absolute/protocol-relative paths
  • Single/double/no quotes
  • Performance: 100 scripts in <100ms

GLightbox Scenario: Documents the exact issue from #173 with 4 solution options

Related: #173


🔧 Dependency Updates

  • orchestra/testbench → ^10.6.0
  • actions/checkout → v5
  • actions/cache → v4
  • actions/github-script → v8

📊 Test Results


🚀 Impact

Performance

  • ✅ No performance regressions
  • ✅ Large HTML processing verified (20,000 lines)
  • ✅ PCRE safeguards prevent blank pages

Stability

  • ✅ JavaScript comment removal no longer breaks code
  • ✅ DNS prefetch no longer interferes with SEO/structured data
  • ✅ Robust error handling for edge cases

Compatibility

  • ✅ Laravel 10, 11, 12
  • ✅ PHP 8.2, 8.3
  • ✅ All existing functionality preserved

📝 Breaking Changes

None - This is a bug fix release maintaining full backward compatibility.


🎯 Closed Issues

  • Closes #173 (DeferJavascript + GLightbox ReferenceError)
  • Closes #178 (Laravel 10 compatibility - already supported)
  • Closes #179 (InsertDNSPrefetch + JSON-LD)
  • Closes #180 (CollapseWhitespace blank page)
  • Closes #182 (Laravel 10 composer.json)
  • Closes #184 (Large HTML comments not removed)
  • Closes #187 (Laravel 8 blank page - Laravel 8 EOL)

📦 Installation

composer require vinkius-labs/laravel-page-speed

Or update your existing installation:

composer update vinkius-labs/laravel-page-speed

🔗 Links


👥 Contributors

@renatomarinho - All bug fixes and test coverage improvements


Thank you to everyone who reported issues and helped make this package more robust! 🙏