Home / Snippets / Speed up Laravel with Laravel Page Speed
Speed up Laravel with Laravel Page Speed cover

Speed up Laravel with Laravel Page Speed

592

3 years ago

0 comments

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).
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this