Increase Website Speed Laravel 5.x | Optimize and Improve Laravel website

Increase Website Speed Laravel 5.x | Optimize and Improve Laravel website

How to Increase Laravel website speed and optimize the speed performance with laravel-page-speed package.




Do you have a website Build in laravel? and want to improve website speed and page speed. Speed Means Website with very good load time that means should take very less time to load. It’s one of the measure criteria in current scenario for improving search engines rankings. Sometimes your codes are not minified so that’s the one of the biggest reason is to increase website load time. If your website Build in laravel framework of PHP, So there are some packages which can minify your code automatically.

So in this quick write, I am going to share with you one of the Package called laravel-page-speed. You can install it with your composer. Generally, it will minify your HTML output and will optimize your web page. they also minify JS and CSS files and provide the feature to take less load time for the Laravel web apps.

Before Code optimization:-

How to Increase Laravel website speed and optimize the speed performace with laravel-page-speed package

After Code Optimizations

How to Increase Laravel website speed and optimize the speed performace with laravel-page-speed package

#1:- SO First, you need to install the package via composer just write command on your terminal:


$ composer require renatomarinho/laravel-page-speed

If you are using Laravel 5.5 version

then You don’t have to do anything else, this package uses the Package Auto-Discovery feature, and should be available as soon as you install it via Composer.

If you are using Laravel 5.4 or 5.3

#2:- You need to add the following Service Provider to your config/app.php:

 RenatoMarinho\LaravelPageSpeed\ServiceProvider::class 

like below snippet.

'providers' => [
  ....
  RenatoMarinho\LaravelPageSpeed\ServiceProvider::class
]

#3:- Need to Publish configuration file


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

#4:- Register Middlewares

Edit your app/Http/Kernel.php and the following middlewares.

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

#5:- Create route file

Now, we need to create route to display layout view file. you can create in routes/web.php file and add following route.

Route::get('pageSpeedTest', function () {
    return view('pageSpeedTest');
});

And Then create a view pageSpeedTest.blade.php inside the resources->view



<html>
<head>
<title>Technology shouters lab - Learn web Development,Php,Python,Html,JQuery,Javascript,HTML5,Css3</title>
 <meta charset="UTF-8">
  <meta name="description" content="Learn web Development,Php,Python,Html,JQuery,Javascript,HTML5,Css3,Blogging, Placement,Career,Sample papers">
  <meta name="keywords" content="web Development, Php,Python,Html,JQuery,Javascript,HTML5,Css3,Blogging, Placement,Career,Sample papers">
  <meta name="author" content="Krishna ballabh Gupta">
  <!--<meta name="viewport" content="width=device-width, initial-scale=1.0">-->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.css" rel="stylesheet">  
<link href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.min.css" rel="stylesheet"> 
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.min.js"></script>
<script>
$(document).ready(function() {
    $('#example').DataTable();
} );
</script>
</head>
<body>
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Date</th>
                <th>Title</th>
                <th>Author</th>
                <th>Article link</th>
                <th>Demo</th>
                <th>Source Code</th>
            </tr>
        </thead>
        <tfoot>
            <!-- <tr>
                <th>06-09-2017</th>
                <th>Facebook Like Face Detection Script in JQuery – Download Source Code</th>
                <th>Krishna Gupta</th>
                <th><a href="https://www.technologyshouters.com/facebook-like-face-detection-script-in-jquery/">Article</a></th>
                <th><a href="http://www.technologyshouters.com/facedetect/"></a>Demo</th>
                <th>Salary</th>
            </tr> -->
        </tfoot>
        <tbody>
           <tr>
                <th>06-09-2017</th>
                <th>Facebook Like Face Detection Script in JQuery – Download Source Code</th>
                <th>Krishna Gupta</th>
                <th><a href="https://www.technologyshouters.com/facebook-like-face-detection-script-in-jquery/">Article</a></th>
                <th><a href="http://www.technologyshouters.com/facedetect/">Demo</a></th>
                <th><a href="#">Download</a></th>
            </tr>
            <tr>
                <th>08-09-2017</th>
                <th>Laravel 5.5 CRUD application from Scratch – Complete Source code</th>
                <th>Krishna Gupta</th>
                <th><a href="https://www.technologyshouters.com/laravel-5-5-crud-application-scratch-complete-source-code/">Article</a></th>
                <th><a href="#">Demo</a></th>
                <th><a href="#">Download</a></th>
            </tr>
             <tr>
                <th>10-09-2017</th>
                <th>Login and Register in Laravel 5.5 – Simple & Complete Guide</th>
                <th>Krishna Gupta</th>
                <th><a href="https://www.technologyshouters.com/login-and-register-in-laravel-5-5-simple-complete-guide/">Article</a></th>
                <th><a href="#">Demo</a></th>
                <th><a href="#">Download</a></th>
            </tr>
             <tr>
                <th>12-09-2017</th>
                <th>Upload Profile picture in Laravel 5.5 – Download Source Code</th>
                <th>Krishna Gupta</th>
                <th><a href="https://www.technologyshouters.com/upload-profile-picture-in-laravel-5-5/">Article</a></th>
                <th><a href="#">Demo</a></th>
                <th><a href="#">Download</a></th>
            </tr>
             <tr>
                <th>13-09-2017</th>
                <th>Create Your Own Web Text Editor Using HTML, CSS and Javascript.</th>
                <th>Krishna Gupta</th>
                <th><a href="https://www.technologyshouters.com/create-code-editor-using-html-css-javascript/">Article</a></th>
                <th><a href="#">Demo</a></th>
                <th><a href="#">Download</a></th>
            </tr>
             <tr>
                <th>18-09-2017</th>
                <th>Build a Javascript snake game Easily – Technology Shouters</th>
                <th>Krishna Gupta</th>
                <th><a href="https://www.technologyshouters.com/build-javascript-snake-game-easily-technology-shouters/">Article</a></th>
                <th><a href="#">Demo</a></th>
                <th><a href="#">Download</a></th>
            </tr>
            <tr>
                <th>20-09-2017</th>
                <th>Delete Multiple Records At Once in CodeIgniter php Framework</th>
                <th>Krishna Gupta</th>
                <th><a href="https://www.technologyshouters.com/delete-multiple-records-codegnitor-php-framework/">Article</a></th>
                <th><a href="#">Demo</a></th>
                <th><a href="#">Download</a></th>
            </tr>
            <tr>
                <th>20-09-2017</th>
                <th>How to : Create Beautiful Analog & Digital Clock in HTML5 and CSS3</th>
                <th>Krishna Gupta</th>
                <th><a href="https://www.technologyshouters.com/analog-digital-clock-in-html5-and-css3/">Article</a></th>
                <th><a href="#">Demo</a></th>
                <th><a href="#">Download</a></th>
            </tr>
             <tr>
                <th>23-09-2017</th>
                <th>Search functionality in Laravel 5.5 With Pagination – Source Code</th>
                <th>Krishna Gupta</th>
                <th><a href="">Article</a></th>
                <th><a href="#">Demo</a></th>
                <th><a href="#">Download</a></th>
            </tr>
        </tbody>
    </table>
</body>
</html>

## This package also provide

Disable Service

You would probably like to set up the local environment so do like that.

//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 package to skip some routes so you can do in this way.


//config/laravel-page-speed.php

//You can use * as a wildcard.

'skip' => [
    '*.pdf', //Ignore all routes with final .pdf
    '*/downloads/*',//Ignore all routes that contain 'downloads'
];

Krishna Gupta

Krishna Ballabh Gupta is a Gold Medalist Full Stack Developer & Algorithm Designer and Founder of TechnologyShouters. He generally Blogs about Python, JavaScript, jQuery, AngularJS, Database, PHP, AJAX and something that interesting.

Related Posts

Create Account



Log In Your Account



1Subscribe to Our Live Updates.