Posts Learn Components Snippets Categories Tags 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

37 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).

Snippets by

PostSrc poster

PostSrc

Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

Load comments for Speed up Laravel with Laravel Page Speed

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets

More