Posts Learn Components Snippets Categories Tags Tools About
/

Speed up Laravel with Laravel Page Speed

Learn how to speed up Laravel application by minify HTML on demand, remove comments, inline CSS, defer Javascript files, collapse whitespace and more

Created on Aug 03, 2021

574 views

One of the ways to speed up your Laravel application is to make use Laravel Page Speed package by Renato Marinho.

In this snippet, you will learn how to speed up Laravel applications by minify HTML on demand, remove comments, inline CSS, defer Javascript files, collapse whitespace, and more.

1 - Install the Package with Composer
The first step is to install the package using composer. By default this will install the latest version of the package.
composer require renatomarinho/laravel-page-speed

2 - Publish Configuration File
Do publish the configuration file to change the settings whenever necessary. It will be handly for later so run the command below.
php artisan vendor:publish --provider="RenatoMarinho\LaravelPageSpeed\ServiceProvider"

3 - Enable the Optimization
To enable the optimization you just have to include the middleware for the necessary part that you want to optimize.
<?php # app/Http/Kernel.php

protected $middleware = [
    # your other middleware here...
    \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,
]

To learn more about the middleware details you can just head over to the documentation on GitHub page (Middleware Details).

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for Speed up Laravel with Laravel Page Speed

)