How to optimize website speed and performance in Laravel?
In this post we will give you information about How to optimize website speed and performance in Laravel?. Hear we will give you detail about How to optimize website speed and performance in Laravel?And how to use it also give you demo for it if it is necessary.
It is very important for every website to quick load that means your website should load in few seconds like 4 or 5. We are always fetching issues about page speed like how to increase website speed in laravel, how to reduce loading time of website in laravel, is it possible speed up php execution time of my website, how to optimize php laravel script to increase speed, how to speed up web browsing in laravel. So basically you have several question regarding to improve your website performance in laravel.
However, There are several composer packages available for increase website page speed in php laravel. So here i found “laravel-page-speed” composer package for 35%+ optimization of your website.
laravel-page-speed package will minify HTML output and it can be optimization your web page. laravel-page-speed package will delete unused attributes in HTML tags, delete unused quotes in HTML tags, delete unused prefixes from URLs, delete unused whitespace in HTML, delete HTML comments. Also there are several feature. They also minify css and minify js files. There are several things done with this page and i am sure it make better performance at it was before.
Here, i will give you very small example with screen shot. I created simple bootstrap file and with simple table. If i see in “CTRL + u” and see source code then i can see too many white space and if anything unused attribute etc. After used this package you can see on source all white space remove and clean with quick run code.
So here i attach both small and simple example screen shot, so you can understand how it can help you. After that you can see how it works.
Before:
After:
As you can see how it optimization and help you. So just follow few step and get simple example:
Step 1: Install laravel-page-speed Composer Package
first thing is that we have to add laravel-page-speed package for improve page speed so one your cmd or terminal and fire bellow command, Make sure laravel-page-speed package support laravel 5.3, laravel 5.4, laravel 5.5 and laravel 5.5 + version of laravel.
composer require renatomarinho/laravel-page-speed
After successfully install package, open config/app.php file and add service provider and alias.
config/app.php
'providers' => [
....
RenatoMarinhoLaravelPageSpeedServiceProvider::class
]
.....
You can publish the default configuration file by following command:
php artisan vendor:publish --provider="RenatoMarinhoLaravelPageSpeedServiceProvider"
After that you have to register your middleware on Kernel.php file so, do like as bellow:
app/Http/Kernel.php
<?php
namespace AppHttp;
use IlluminateFoundationHttpKernel as HttpKernel;
class Kernel extends HttpKernel
{
......
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
.....
RenatoMarinhoLaravelPageSpeedMiddlewareInlineCss::class,
RenatoMarinhoLaravelPageSpeedMiddlewareElideAttributes::class,
RenatoMarinhoLaravelPageSpeedMiddlewareInsertDNSPrefetch::class,
RenatoMarinhoLaravelPageSpeedMiddlewareRemoveComments::class,
RenatoMarinhoLaravelPageSpeedMiddlewareTrimUrls::class,
RenatoMarinhoLaravelPageSpeedMiddlewareRemoveQuotes::class,
RenatoMarinhoLaravelPageSpeedMiddlewareCollapseWhitespace::class,
],
.....
];
.....
}
Step 2: Make Route
In this is step we need to create route display simple layout file. so open your routes/web.php file and add following route.
routes/web.php
Route::get('mySource', function () {
return view('mySource');
});
Step 3: Create Blade File
In Last step, let’s create mySource.blade.php(resources/views/mySource.blade.php) for layout and we will write design code here and put following code:
resources/views/mySource.blade.php
<!DOCTYPE html>
<html>
<head>
<title>My Source</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
<div >
<h1>My Source</h1>
<table >
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Haresh</td>
<td>haresh@gmail.com</td>
</tr>
<tr>
<td>2</td>
<td>Vimal</td>
<td>vimal@gmail.com</td>
</tr>
<tr>
<td>3</td>
<td>Harshad</td>
<td>harshad@gmail.com</td>
</tr>
<tr>
<td>4</td>
<td>Raju</td>
<td>raju@gmail.com</td>
</tr>
<tr>
<td>5</td>
<td>Paresh</td>
<td>paresh@gmail.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Now, you are ready to run example.
You can get more information about laravel-page-speed plugin from here : laravel-page-speed
I hope it can help you….
Hope this code and post will helped you for implement How to optimize website speed and performance in Laravel?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs