PHPackages                             tsekka/prerender - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tsekka/prerender

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tsekka/prerender
================

Prerender

0.2.6(3y ago)073MITPHPPHP &gt;=8.0

Since Dec 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/tsekka/laravel-prerender)[ Packagist](https://packagist.org/packages/tsekka/prerender)[ Docs](https://github.com/tsekka/prerender)[ RSS](/packages/tsekka-prerender/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (14)Used By (0)

Prerender &amp; cache your SPA pages for crawlers on Laravel
============================================================

[](#prerender--cache-your-spa-pages-for-crawlers-on-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4cf6fbf363916ec42c6db81e00326b8d3e0d7c7e8eb7d0c1bd1549814f1066bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7473656b6b612f70726572656e6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tsekka/prerender)[![Total Downloads](https://camo.githubusercontent.com/b1d6ff1f1a252c6ca4feb8e713e2e562789f9efd31a5166996c4104984f42d63/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7473656b6b612f70726572656e6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tsekka/prerender)

This package intends to make it easier to serve prerendered pages to crawlers for better SEO.

You could make use of it if

- you are running Laravel as backend for your single-page webapp or
- parts of your Laravel app are generated using Javascript.

It could be used as a

- middleware for third-party prerender service (like prerender.io) but
- it can also cache prerendered responses &amp; keep cached responses up to date (for running your local prerender server).

Installation
------------

[](#installation)

Via Composer

```
$ composer require tsekka/prerender
```

Preparing the database
----------------------

[](#preparing-the-database)

The package loads migrations

```
php artisan migrate

```

Publishing the config file
------------------------------------------------------------------

[](#publishing-the-config-file)

Publishing the config file is optional.

```
php artisan vendor:publish --provider="Tsekka\Prerender\PrerenderServiceProvider" --tag="config"

```

 Registering prerender middleware
---------------------------------------------------------------------

[](#-registering-prerender-middleware)

Enable prerendering for all routes by adding `PRERENDER_REGISTER_GLOBALLY=true` in your .env file; or add middleware to specific routes:

```
// app/Http/Kernel.php
  protected $routeMiddleware = [
    // ...
    'prerender' =>
        \Tsekka\Prerender\Http\Middleware\PrerenderMiddleware::class,
  ];

// routes/web.php
Route::get('/{path?}', 'SPAController')->where('path', '.*')
    ->middleware('prerender');
```

Prerendering by third party service
-----------------------------------

[](#prerendering-by-third-party-service)

***By using prerender.io or similar service, you don't have to install node server and headless chrome by yourself.***

The primary use case of this package is to make it easier to run custom prerender server &amp; cache it's responses. However, the easiest way to start prerendering the pages for crawlers is by using third-party service like prerender.io.

1. Register at prerender.io or at another similar service and follow their instructions.
2. Set prerenderer's url `PRERENDER_URL=https://service.prerender.io` and token `PRERENDER_TOKEN=YOUR-THIRD-PARTY-TOKEN` (add this in your .env file)
3. Prerender.io already caches the pages for speed, so you can turn off local cache `PRERENDER_CACHE_TTL=null` (.env)
4. [Register the middleware](#middleware) and you're good to go!

Running your own prerender service
----------------------------------

[](#running-your-own-prerender-service)

**To run your own prerender service, you must have Node, headless Chrome and their dependencies installed in your webserver.**

Prerender.io has open-sourced [node server](https://github.com/prerender/prerender) that you can use to prerender the pages at your server.

Here's how you can make use of it:

1. Install and run prerenderer's node server.
    - Clone it from this package's directory (`cp -r ./vendor/tsekka/prerender/prerenderer ./prerenderer`) and install dependencies `cd prerenderer && npm install`.
    - You can also follow [this quick tutorial](/prerenderer/readme.md) which includes instructions how to install headless Chrome browser on Debian-based Linux distributions.
2. Set prerenderer's url to url of your prerenderer's service. Eg. if you're running it locally, then add `PRERENDER_URL=http://localhost:3000` to your .env file.
3. Decide if you will keep the prerender server constantly running or if you would rather start the server for the duration of [schedule command](#caching-schedule).
    - If you will keep the server constantly running, then start the prerendering server `node server.js` and make sure that the node server will re-start even after webserver is rebooted.
    - If you would rather start the server only for the duration of prerender command, then set `PRERENDER_RUN_LOCAL_SERVER=true` in your .env file.
4. [Register the middleware](#middleware)
5. Prerendering the page on-demand can be slow and therefore, by default the pages will be [cached](#caching).
6. It's recommended that you [set up the schedule to re-cache](#caching-schedule) the prerendered pages.

###  Caching prerendered responses

[](#-caching-prerendered-responses)

Prerendering the page can take up to few seconds or even more.

Therefore the pages will be cached by default for 1 week.

You can change cache time-to-live and cache driver by setting .env variables `PRERENDER_CACHE_TTL` and `PRERENDER_CACHE_DRIVER` or by [publishing](#publish-config) and modifying the config file.

*If you're using third-party service like Prerender.io, then the responses are probably already cached, so you can turn off local cache (add `PRERENDER_CACHE_TTL=null` to your .env).*

#### Running cache command

[](#running-cache-command)

You can run `php artisan prerender:cache` command to cache all pages that are defined in array of cacheable urls.

By default, the cache command only caches urls that have not been cached yet or whose cache ttl have already expired. You can run cache command with --force option (`php artisan prerender:cache --force`) to re-cache all urls.

#### Keeping prerendered pages up to date

[](#keeping-prerendered-pages-up-to-date)

Prerendering the page on-demand can be slow and it's therefore recommended to keep fresh copy of pages constantly in cache.

##### You could set up event listener to keep the prerendered page in sync

[](#you-could-set-up-event-listener-to-keep-the-prerendered-page-in-sync)

```
    // 1. Set up event-listener
    // 2. Inside your listener:
    public function handle($event)
    {
       return \Artisan::call('prerender:cache', [
                'url' => '/your-model-resource-url',
                '--force' => true,
                '--log' => false,
        ]);
    }
```

##### Or schedule prerendering and recaching on specified time

[](#or-schedule-prerendering-and-recaching-on-specified-time)

```
    // app/Console/Kernel.php
    protected function schedule(Schedule $schedule)
    {
        // Daily re-cache all urls that's cache-time-to-live is expired
         $schedule->command('prerender:cache')->dailyAt("02:00");

        // Daily re-cache all urls
         $schedule->command('prerender:cache --force')->dailyAt("02:00");
    }
```

####  Providing list of urls to cache

[](#-providing-list-of-urls-to-cache)

Each time crawler visits the url that matches all requirements for it to be prerendered, the prerendered response will be cached and the url of request will be recorded in database.

So by default, before you actually start using the package, the list will be empty and the urls will be prerendered at the time of request (and therefore the request time could be quite slow, as prerendering takes time).

If you would like to cache the pages only [on demand](#on-demand) or you would like to keep response time low even on first crawler visit, then you should provide a class &amp; method name that returns array of of urls by publishing config file and modifying it's `cacheable_urls` value.

 Pruning old entries
-----------------------------------------------------

[](#-pruning-old-entries)

The package logs all crawler visits into database.

Use `php artisan prerender:prune` command to clear old entries.

You can also schedule the artisan command:

```
    // app/Console/Kernel.php
    protected function schedule(Schedule $schedule)
    {
        // Daily prune all crawler visit entries older than 1 month
        $schedule->command('prerender:prune "1 month"')->daily();
    }
```

Whitelisting urls
-----------------

[](#whitelisting-urls)

Whitelist paths or patterns. You can use asterix syntax. If a whitelist is supplied, only url's containing a whitelist path will be prerendered. An empty array means that all URIs will pass this filter. Note that this is the full request URI, so including starting slash and query parameter string.

```
// prerender.php:
'whitelist' => [
    '/frontend/*' // only prerender pages starting with '/frontend/'
],
```

Blacklisting urls
-----------------

[](#blacklisting-urls)

Blacklist paths to exclude. You can use asterix syntax. If a blacklist is supplied, all url's will be prerendered except ones containing a blacklist path. By default, a set of asset extentions are included (this is actually only necessary when you dynamically provide assets via routes). Note that this is the full request URI, so including starting slash and query parameter string.

```
// config/prerender.php
'blacklist' => [
    '/api/*' // do not prerender pages starting with '/api/'
    // ...
],
```

Other resources
---------------

[](#other-resources)

If you don't know why or when you should prerender your SPA apps, then there are some resources for you to check out:

- [blog post at netlify.com](https://www.netlify.com/blog/2016/11/22/prerendering-explained/),
- [prerender.io](https://prerender.io/)
- [stackoverflow question](https://stackoverflow.com/questions/58107986/csr-vs-ssr-vs-pre-render-which-one-should-i-choose).

Contributing
------------

[](#contributing)

This package is under development. Contributions are appreciated and will be credited.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- Forked from Jeroen Noten's [Laravel-Prerender](https://github.com/jeroennoten/Laravel-Prerender)

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Total

12

Last Release

1290d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fd70f75eaf1a9e85571351602af4bf02b8e5d963e91a9a95e60ff418da84008a?d=identicon)[tsekka](/maintainers/tsekka)

---

Top Contributors

[![tsekka](https://avatars.githubusercontent.com/u/43533692?v=4)](https://github.com/tsekka "tsekka (36 commits)")

---

Tags

laravelprerender

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tsekka-prerender/health.svg)

```
[![Health](https://phpackages.com/badges/tsekka-prerender/health.svg)](https://phpackages.com/packages/tsekka-prerender)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[nutsweb/laravel-prerender

Laravel middleware for prerendering javascript-rendered pages on the fly for SEO

279165.5k1](/packages/nutsweb-laravel-prerender)[nativephp/mobile

NativePHP for Mobile

82724.0k43](/packages/nativephp-mobile)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[adrianorosa/laravel-geolocation

Laravel Geo Location package to get details for a given IP Address

6593.3k1](/packages/adrianorosa-laravel-geolocation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
