Download the PHP package sgtaziz/blazar without Composer
On this page you can find all versions of the php package sgtaziz/blazar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sgtaziz/blazar
More information about sgtaziz/blazar
Files in sgtaziz/blazar
Package blazar
Short Description pre-render pages on the fly
License MIT
Homepage https://github.com/ctf0/Blazar
Informations about the package blazar
Blazar
Automate pre-rendering pages on the fly through utilizing PhantomJs which runs in the background when needed without adding any overhead to the server nor to the user experience.
Installation
-
install PhantomJs
-
composer require ctf0/blazar
-
(Laravel < 5.5) add the service provider to
config/app.php
- publish the package assets
php artisan vendor:publish --provider="ctf0\Blazar\BlazarServiceProvider"
-
add the middlewares to
app/Http/Kernel.php
- the package use caching through Redis to store the rendered results, so make sure to check the docs for installation & configuration.
Config
config/blazar.php
Usage
-
we use Queues to pre-render the visited pages in the background for more than one reason
- avoid latency when the page is being accessed for the first time.
- don't keep the user waiting in case
PhantomJs
took long to render the page or when something goes wrong. - after
PhantomJs
has finished rendering, the page is cached to optimize server load even further. - make your website SEO friendly, because instead of serving the normal pages that usually produce issues for crawlers, we are now serving the pre-renderd version. ReadMore
- even for websites with some traffic, we are still going to process each visited page without any problems.
Render Pages Automatically
Atm in order to pre-render any page, it have to be visited first but if you want to make sure that all is working from day one, you can use the excellent package laravel-link-checker by Spatie
-
which by simply running
php artisan link-checker:run
you will- check which "url/link" on the website is not working.
- pre-render all pages at once.
Flushing The Cache
- to clear the whole package cache, you can use
or from within your app
Bots Only
we now use CrawlerDetect instead of relying on '\?_escapedfragment'
if you decided to pre-render the pages for bots only, no need to the run the queue as the page will remain busy "stalled response" until rendered by PhantomJs
, which happens on the fly.
however because we are caching the result, so this will only happen once per page.
also note that we are saving the page cache equal to the url so even if you switched off the bots_only
option, if the page is cached, we will always serve the cached result.
Notes
Why PhantomJs
I've tried both usus & puppeteer,
And my only take that both needs to run an instance of Chrome, while i wanted to keep the whole thing as hidden and as low-leveled as possible.
however if anyone knows how to get any to work as "PhantomJs", am all ears :ear: .
Queues
the worker should only fires when a url is visited & if this url is not cached,
however if you have an unfinished old process, the queue will start processing pages on its own, so to fix that, simply restart the queue server beanstalkd, redis, etc...
Auth
as i dont know how to make laravel think that a page visited through phantomjs is the same as the current logged in user.
so trying to pre-render pages with auth
middleware will be cashed as if the user was redirected to the home page or whatever you've set to redirectTo under
Constollers/Auth/LoginController.php
& Middleware/RedirectIfAuthenticated.php
so to solve that, simply add dont-pre-render
middleware to those routes and everything will work as expected.
also make sure to add the same middleware to any route that needs fresh csrf-token for each user "login, register, etc.." to avoid getting CSRF Token Mismatch
for other users trying to use those pages.
More Reading
All versions of blazar with dependencies
illuminate/support Version ^5.4 || ^5.5
jaybizzle/laravel-crawler-detect Version ^1.0
ctf0/package-changelog Version ^1.0