PHPackages                             gopalindians/laravel-page-speed - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gopalindians/laravel-page-speed

ActiveLibrary

gopalindians/laravel-page-speed
===============================

Laravel Page Speed

11.3k—4.9%PHP

Since Mar 18Pushed 5d agoCompare

[ Source](https://github.com/gopalindians/laravel-page-speed)[ Packagist](https://packagist.org/packages/gopalindians/laravel-page-speed)[ RSS](/packages/gopalindians-laravel-page-speed/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

 [![Laravel Page Speed logo](https://raw.githubusercontent.com/renatomarinho/laravel-page-speed/master/art/logo.png)](https://raw.githubusercontent.com/renatomarinho/laravel-page-speed/master/art/logo.png)

[![Build Status](https://camo.githubusercontent.com/f5c34e6a46a5b33df0a95eadb1a8ca53bb7c765bff2c7339688568b385f4f761/68747470733a2f2f7472617669732d63692e6f72672f72656e61746f6d6172696e686f2f6c61726176656c2d706167652d73706565642e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/renatomarinho/laravel-page-speed)[![Latest Stable Version](https://camo.githubusercontent.com/b39bfb834b6b3202c481a3dfafc9219455705776302d9f8c0cfb60686d97fbaa/68747470733a2f2f706f7365722e707567782e6f72672f72656e61746f6d6172696e686f2f6c61726176656c2d706167652d73706565642f76657273696f6e)](https://packagist.org/packages/gopalindians/laravel-page-speed)[![Total Downloads](https://camo.githubusercontent.com/96102a87f6b994462c49145cef23049731c8549adc67b65a1d3b0a85c6d6af9c/68747470733a2f2f706f7365722e707567782e6f72672f676f70616c696e6469616e732f6c61726176656c2d706167652d73706565642f646f776e6c6f616473)](https://packagist.org/packages/gopalindians/laravel-page-speed)[![License](https://camo.githubusercontent.com/da959a0a685e3901ba6f180c1685510d8b89a63a8ae6946b75f1181ff721581f/68747470733a2f2f706f7365722e707567782e6f72672f676f70616c696e6469616e732f6c61726176656c2d706167652d73706565642f6c6963656e7365)](https://packagist.org/packages/gopalindians/laravel-page-speed)

Laravel Page Speed
==================

[](#laravel-page-speed)

Simple package to minify HTML output on demand which results in a 35%+ optimization. Laravel Page Speed was created by [Renato Marinho](https://github.com/renatomarinho), and currently maintained by [João Roberto P. Borges](https://github.com/joaorobertopb), [Lucas Mesquita Borges](https://github.com/lucasMesquitaBorges) and [Renato Marinho](https://github.com/renatomarinho).

Installation
------------

[](#installation)

> **Requires:**

- **[PHP 8.0+](https://php.net/releases/)**
- **[Laravel 11.0+](https://github.com/laravel/laravel)**

You can install the package via composer:

```
composer require gopalindians/laravel-page-speed
```

OR

```
composer require gopalindians/laravel-page-speed:dev-master
```

This package supports Laravel [Package Discovery](https://laravel.com/docs/6.0/packages#package-discovery).

### Publish configuration file

[](#publish-configuration-file)

`php artisan vendor:publish --provider="RenatoMarinho\LaravelPageSpeed\ServiceProvider"`

Do not forget to register middlewares
-------------------------------------

[](#do-not-forget-to-register-middlewares)

Next, the `\RenatoMarinho\LaravelPageSpeed\Middleware\CollapseWhitespace::class` and other middleware must be registered in the kernel, for example:

In laravel 12

```
//bootstrap/app.php
return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        api: __DIR__.'/../routes/api.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->appendToGroup('web',\RenatoMarinho\LaravelPageSpeed\Middleware\InlineCss::class);
        $middleware->appendToGroup('web',\RenatoMarinho\LaravelPageSpeed\Middleware\ElideAttributes::class);
        $middleware->appendToGroup('web',\RenatoMarinho\LaravelPageSpeed\Middleware\InsertDNSPrefetch::class);
        $middleware->appendToGroup('web',\RenatoMarinho\LaravelPageSpeed\Middleware\RemoveComments::class);
        $middleware->appendToGroup('web',\RenatoMarinho\LaravelPageSpeed\Middleware\TrimUrls::class);
        $middleware->appendToGroup('web',\RenatoMarinho\LaravelPageSpeed\Middleware\RemoveQuotes::class);
        $middleware->appendToGroup('web',\RenatoMarinho\LaravelPageSpeed\Middleware\CollapseWhitespace::class);
        $middleware->appendToGroup('web',\RenatoMarinho\LaravelPageSpeed\Middleware\DeferJavascript::class);

    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();
```

In laravel 10 and below

```
//app/Http/Kernel.php

protected $middleware = [
    ...
    \RenatoMarinho\LaravelPageSpeed\Middleware\InlineCss::class,
    \RenatoMarinho\LaravelPageSpeed\Middleware\ElideAttributes::class,
    \RenatoMarinho\LaravelPageSpeed\Middleware\InsertDNSPrefetch::class,
    \RenatoMarinho\LaravelPageSpeed\Middleware\RemoveComments::class,
    //\RenatoMarinho\LaravelPageSpeed\Middleware\TrimUrls::class,
    //\RenatoMarinho\LaravelPageSpeed\Middleware\RemoveQuotes::class,
    \RenatoMarinho\LaravelPageSpeed\Middleware\CollapseWhitespace::class, // Note: This middleware invokes "RemoveComments::class" before it runs.
    \RenatoMarinho\LaravelPageSpeed\Middleware\DeferJavascript::class,
]
```

Middlewares Details
-------------------

[](#middlewares-details)

### \\RenatoMarinho\\LaravelPageSpeed\\Middleware\\RemoveComments::class

[](#renatomarinholaravelpagespeedmiddlewareremovecommentsclass)

The **RemoveComments::class** filter eliminates HTML, JS and CSS comments. The filter reduces the transfer size of HTML files by removing the comments. Depending on the HTML file, this filter can significantly reduce the number of bytes transmitted on the network.

### \\RenatoMarinho\\LaravelPageSpeed\\Middleware\\CollapseWhitespace::class

[](#renatomarinholaravelpagespeedmiddlewarecollapsewhitespaceclass)

The **CollapseWhitespace::class** filter reduces bytes transmitted in an HTML file by removing unnecessary whitespace. This middleware invoke **RemoveComments::class** filter before executation.

> **Note**: Do not register the "RemoveComments::class" filter with it. Because it will be called automatically by "CollapseWhitespace::class"

#### Before

[](#before)

[![Before of Laravel Page Speed](https://camo.githubusercontent.com/b0141aa95fae5e66399f5d3dcdb20505e57860a0f80e7dd46b0c0e97ebcdb79b/68747470733a2f2f692e696d6775722e636f6d2f634e334d5759682e706e67)](https://camo.githubusercontent.com/b0141aa95fae5e66399f5d3dcdb20505e57860a0f80e7dd46b0c0e97ebcdb79b/68747470733a2f2f692e696d6775722e636f6d2f634e334d5759682e706e67)

#### After

[](#after)

[![After of Laravel Page Speed](https://camo.githubusercontent.com/629e6e0b38a0f6798828033cdb48ec72ea6b22eb5af64a8c50f2f24800f132c1/68747470733a2f2f692e696d6775722e636f6d2f494b574b4c6b4c2e706e67)](https://camo.githubusercontent.com/629e6e0b38a0f6798828033cdb48ec72ea6b22eb5af64a8c50f2f24800f132c1/68747470733a2f2f692e696d6775722e636f6d2f494b574b4c6b4c2e706e67)

### \\RenatoMarinho\\LaravelPageSpeed\\Middleware\\RemoveQuotes::class

[](#renatomarinholaravelpagespeedmiddlewareremovequotesclass)

The **RemoveQuotes::class** filter eliminates unnecessary quotation marks from HTML attributes. While required by the various HTML specifications, browsers permit their omission when the value of an attribute is composed of a certain subset of characters (alphanumerics and some punctuation characters).

Quote removal produces a modest savings in byte count on most pages.

### \\RenatoMarinho\\LaravelPageSpeed\\Middleware\\ElideAttributes::class

[](#renatomarinholaravelpagespeedmiddlewareelideattributesclass)

The **ElideAttributes::class** filter reduces the transfer size of HTML files by removing attributes from tags when the specified value is equal to the default value for that attribute. This can save a modest number of bytes, and may make the document more compressible by canonicalizing the affected tags.

### \\RenatoMarinho\\LaravelPageSpeed\\Middleware\\InsertDNSPrefetch::class

[](#renatomarinholaravelpagespeedmiddlewareinsertdnsprefetchclass)

The **InsertDNSPrefetch::class** filter Injects tags in the HEAD to enable the browser to do DNS prefetching.

DNS resolution time varies from &lt;1ms for locally cached results, to hundreds of milliseconds due to the cascading nature of DNS. This can contribute significantly towards total page load time. This filter reduces DNS lookup time by providing hints to the browser at the beginning of the HTML, which allows the browser to pre-resolve DNS for resources on the page.

### ⚠️ \\RenatoMarinho\\LaravelPageSpeed\\Middleware\\TrimUrls::class,

[](#️-renatomarinholaravelpagespeedmiddlewaretrimurlsclass)

The **TrimUrls::class** filter trims URLs by resolving them by making them relative to the base URL for the page.

> **Warning**: **TrimUrls::class** is considered **medium risk**. It can cause problems if it uses the wrong base URL. This can happen, for example, if you serve HTML that will be pasted verbatim into other HTML pages. If URLs are trimmed on the first page, they will be incorrect for the page they are inserted into. In this case, just disable the middleware.

### \\RenatoMarinho\\LaravelPageSpeed\\Middleware\\InlineCss::class

[](#renatomarinholaravelpagespeedmiddlewareinlinecssclass)

The **InlineCss::class** filter transforms the inline "style" attribute of tags into classes by moving the CSS to the header.

### \\RenatoMarinho\\LaravelPageSpeed\\Middleware\\DeferJavascript::class

[](#renatomarinholaravelpagespeedmiddlewaredeferjavascriptclass)

Defers the execution of javascript in the HTML.

> If necessary cancel deferring in some script, use `data-pagespeed-no-defer` as script attribute to cancel deferring.

---

Configuration
-------------

[](#configuration)

After installing package, you may need to configure some options.

### Disable Service

[](#disable-service)

You would probably like to set up the local environment to get a readable output.

```
//config/laravel-page-speed.php

//Set this field to false to disable the laravel page speed service.
'enable' => env('LARAVEL_PAGE_SPEED_ENABLE', true),
```

### Skip routes

[](#skip-routes)

You would probably like to configure the package to skip some routes.

```
//config/laravel-page-speed.php

//You can use * as wildcard.
'skip' => [
    '*.pdf', //Ignore all routes with final .pdf
    '*/downloads/*',//Ignore all routes that contain 'downloads'
    'assets/*', // Ignore all routes with the 'assets' prefix
];
```

By default this field comes configured with some options, so feel free to configure according to your needs...

> *Notice*: This package skip automatically 'binary' and 'streamed' responses. See [File Downloads](https://laravel.com/docs/6.0/responses#file-downloads).

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Contributors
------------

[](#contributors)

- [Caneco](https://twitter.com/caneco) (for the logo)
- [All Contributors](../../contributors)

Inspiration
-----------

[](#inspiration)

#### Mod Page Speed ()

[](#mod-page-speed-httpswwwmodpagespeedcom)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 62% of packages

Maintenance65

Regular maintenance activity

Popularity21

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/db5d05d820dcff11750c95bbc7f80e6554ff619e9ebede8fafab2fbf0b013a72?d=identicon)[gopalindians](/maintainers/gopalindians)

---

Top Contributors

[![joaorobertopb](https://avatars.githubusercontent.com/u/6556083?v=4)](https://github.com/joaorobertopb "joaorobertopb (63 commits)")[![lucasMesquitaBorges](https://avatars.githubusercontent.com/u/42281497?v=4)](https://github.com/lucasMesquitaBorges "lucasMesquitaBorges (19 commits)")[![gopalindians](https://avatars.githubusercontent.com/u/1937433?v=4)](https://github.com/gopalindians "gopalindians (8 commits)")[![vinkla](https://avatars.githubusercontent.com/u/499192?v=4)](https://github.com/vinkla "vinkla (5 commits)")[![stakahashi](https://avatars.githubusercontent.com/u/3667416?v=4)](https://github.com/stakahashi "stakahashi (5 commits)")[![tswestendorp](https://avatars.githubusercontent.com/u/1061961?v=4)](https://github.com/tswestendorp "tswestendorp (5 commits)")[![renatomarinho](https://avatars.githubusercontent.com/u/26571?v=4)](https://github.com/renatomarinho "renatomarinho (3 commits)")[![kenzouno1](https://avatars.githubusercontent.com/u/1946802?v=4)](https://github.com/kenzouno1 "kenzouno1 (2 commits)")[![saifulwebid](https://avatars.githubusercontent.com/u/1644410?v=4)](https://github.com/saifulwebid "saifulwebid (2 commits)")[![gopalsh560](https://avatars.githubusercontent.com/u/183208741?v=4)](https://github.com/gopalsh560 "gopalsh560 (2 commits)")[![percymamedy](https://avatars.githubusercontent.com/u/11259669?v=4)](https://github.com/percymamedy "percymamedy (1 commits)")[![swilla](https://avatars.githubusercontent.com/u/304159?v=4)](https://github.com/swilla "swilla (1 commits)")[![tvbeek](https://avatars.githubusercontent.com/u/2026498?v=4)](https://github.com/tvbeek "tvbeek (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![caneco](https://avatars.githubusercontent.com/u/502041?v=4)](https://github.com/caneco "caneco (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![f-liva](https://avatars.githubusercontent.com/u/346224?v=4)](https://github.com/f-liva "f-liva (1 commits)")[![gofish543](https://avatars.githubusercontent.com/u/10394554?v=4)](https://github.com/gofish543 "gofish543 (1 commits)")[![JapSeyz](https://avatars.githubusercontent.com/u/2234034?v=4)](https://github.com/JapSeyz "JapSeyz (1 commits)")[![lakuapik](https://avatars.githubusercontent.com/u/20186786?v=4)](https://github.com/lakuapik "lakuapik (1 commits)")

---

Tags

laravel11xlaravel12xlaravel13

### Embed Badge

![Health badge](/badges/gopalindians-laravel-page-speed/health.svg)

```
[![Health](https://phpackages.com/badges/gopalindians-laravel-page-speed/health.svg)](https://phpackages.com/packages/gopalindians-laravel-page-speed)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
