eCommerce, Laraship

How to Speed your Laraship Website or Web Application

Background:

As we know, the site speed is becoming the main factor to help to index your website under search engines like Google, and in the article, we will introduce some of the techniques to speed your Laraship website.

As Laraship built on Laravel you will find some of the techniques are part of Laravel engine, what’s nice in Laraship you can utilize Laravel because it hasn’t overridden any of Laravel components or modules.

 

Techniques:

– Disable/completely remove unused plugins:

in Laraship Elite package you will receive more than 50 plugins/themes/payment gateways. so for example, if you want to use or two payment gateways then you can uninstall and remove these files completely, as Composer (Laravel dependancy Manager) is scanning all folders to add an alias as a reference in the dump_autoload files, also this will reduce the processing of scanning the modules for new modules, this also applies for Theme too, as you can keep the admin and frontend theme you’re using and remove the rest.

 

– Enable Caching:

Laravel utilizes Laravel cache methods like Main,Config, View.  in addition to the prevoius, one Laraship has introduced two new caches which are Model and Theme caching.

  1. to Enable Caching:
  • Enable Global Cache in the .env file by changing: APP_ENV to production and APP_DEBUG to false.
  • Enable config and view cache storages by running :
php artisan view:cache 

php artisan config:cache

2. to Enable Theme Caching: you can enable caching at config/theme.php change

'cache' => false,

to

'cache' => true,

Model Caching is already enabled by default in Model Level by adding the cacheable trait to the model, you can find it in action under Setting.php and Menu.php

 

– Configure REDIS as your caching Engine.

Redis has shown a great performance over disk caching or Memcached, so we highly recommend to proceed with Redis to cache your objects. you can refer to the link below for configuring Redis https://www.itechempires.com/2018/06/beginners-guid-to-use-redis-with-laravel-framework/

 

– Enable CDN hosting static content.

CDN can be enabled easily by changing the asset path on your active theme.json to the CDN url. for example

"assetPath": "assets\/themes\/corals-cdn",

to

"assetPath": "https://your-cdn-theme\/assets\/themes\/corals-cdn",

 

– Use Laravel Mix for Your asset management

https://github.com/JeffreyWay/laravel-mix

Laravel Mix is a great tool for managing your assets, please note that Larship themes come as standard asset files, so if you’re looking for Laravel mix you need to override scripts/header.php & footer/scripts.php in your theme and combine the assets in the mix files.

 

One of the more recently popular modules for Apache is mod_pagespeed. It is an output filter for Apache 2.2+ that can be configured through a variety of options through configuration files or a .htaccess file. An “output filter” is a something that transforms the data before it’s sent to the client. In other words, it’s a layer between your website and what the user’s browser receives when they visit your URL.

https://moz.com/blog/use-googles-pagespeed-module-to-dramatically-increase-the-speed-of-your-website

 

  • Add GZIP and Expires header:

Apache:

# BEGIN GZIP
# http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
<IfModule mod_deflate.c>
# Enabling Compression
SetOutputFilter DEFLATE
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml
 
# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
 
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
# END GZIP

# BEGIN Expires headers
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
# END Expires headers

 

for nginx

# BEGIN GZIP
# http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
<IfModule mod_deflate.c>
# Enabling Compression
SetOutputFilter DEFLATE
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml
 
# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
 
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
# END GZIP

# BEGIN Expires headers
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
# END Expires headers

 

Conclusion:

There are many ways for caching Laraship website and the majority are Laravel standards, but what’s more important to understand that Laravel is not a light framework because it has a lot of features integrated, so the server should match the expected traffic, Shared hosting always shows poor performance.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *