renatomarinho / laravel-page-speed by renatomarinho

Laravel Page Speed
1,340,326
2,366
79
Package Data
Maintainer Username: renatomarinho
Maintainer Contact: renato.marinho@s2move.com (Renato Marinho)
Package Create Date: 2017-09-10
Package Last Update: 2024-03-01
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-03-27 03:04:12
Package Statistics
Total Downloads: 1,340,326
Monthly Downloads: 25,047
Daily Downloads: 1,137
Total Stars: 2,366
Total Watchers: 79
Total Forks: 269
Total Open Issues: 44

Laravel Page Speed

Project on GitScrum Build Status License Latest Stable Version Total Downloads

Simple package to minify HTML output on demand which results in a 35%+ optimization.

Installation

You can install the package via composer:

$ composer require renatomarinho/laravel-page-speed

Laravel 5.5 and up

Laravel 5.5 and up uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

Laravel 5.4 or 5.3

Add the Service Provider to the providers array in config/app.php:

RenatoMarinho\LaravelPageSpeed\ServiceProvider::class

This is required for publishing the configuration file:

Publish configuration file

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

Do not forget to register middlewares

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

//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,
]

Before

Before of Laravel Page Speed

After

After of Laravel Page Speed

Roadmap : Filters

Configuration

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

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

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.

Warning

\RenatoMarinho\LaravelPageSpeed\Middleware\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.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Credits

Inspiration

Mod Page Speed (https://www.modpagespeed.com/)

License

The MIT License (MIT). Please see License File for more information.