PHPackages                             zfr/zfr-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. [API Development](/categories/api)
4. /
5. zfr/zfr-prerender

ActiveLibrary[API Development](/categories/api)

zfr/zfr-prerender
=================

Integration with prerender.io service

v3.2.0(7y ago)218.0k6[1 issues](https://github.com/zf-fr/zfr-prerender/issues)MITPHPPHP &gt;=5.4

Since Oct 7Pushed 7y ago4 watchersCompare

[ Source](https://github.com/zf-fr/zfr-prerender)[ Packagist](https://packagist.org/packages/zfr/zfr-prerender)[ Docs](https://github.com/zf-fr/zfr-prerender)[ RSS](/packages/zfr-zfr-prerender/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (11)Used By (0)

ZfrPrerender
============

[](#zfrprerender)

[![Build Status](https://camo.githubusercontent.com/f23a9ef922bf0ff3c4f5adcd3537d45e4bb9931f63df2b79f4b9e7733ac59da3/68747470733a2f2f7472617669732d63692e6f72672f7a662d66722f7a66722d70726572656e6465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/zf-fr/zfr-prerender)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/99668e5c43aa1fc4aac7ceb56e0c929b69d19b6c1fe98efabe542b80ca50c2f7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a662d66722f7a66722d70726572656e6465722f6261646765732f7175616c6974792d73636f72652e706e673f733d66643738656435663664616231346265656633383834656633303733666430636534396532616335)](https://scrutinizer-ci.com/g/zf-fr/zfr-prerender/)[![Coverage Status](https://camo.githubusercontent.com/025f1392dc9f3373352b175055a628ac9a57606b7609dd1b391c3aad92907851/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7a662d66722f7a66722d70726572656e6465722f62616467652e706e67)](https://coveralls.io/r/zf-fr/zfr-prerender)[![Latest Stable Version](https://camo.githubusercontent.com/03195739151ef7dd0472ff49d7d4caf59fe2a5afca9b5acc415e656aee223193/68747470733a2f2f706f7365722e707567782e6f72672f7a66722f7a66722d70726572656e6465722f762f737461626c652e706e67)](https://packagist.org/packages/zfr/zfr-prerender)

Are you using Backbone, Angular, EmberJS, etc, but you're unsure about the SEO implications?

This Zend Framework 2 module uses [Prerender.io](http://www.prerender.io) to dynamically render your JavaScript pages in your server using PhantomJS.

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

[](#installation)

Install the module by typing (or add it to your `composer.json` file):

```
$ php composer.phar require zfr/zfr-prerender:3.*
```

Documentation
-------------

[](#documentation)

### How it works

[](#how-it-works)

1. Check to make sure we should show a prerendered page
    1. Check if the request is from a crawler (either agent string or by detecting *escaped\_fragment* query param)
    2. Check to make sure we aren't requesting a resource (js, css, etc...)
    3. (optional) Check to make sure the url is in the whitelist
    4. (optional) Check to make sure the url isn't in the blacklist
2. Make a `GET` request to the [prerender service](https://github.com/prerender/prerender) (PhantomJS server) for the page's prerendered HTML
3. Return that HTML to the crawler

### Customization

[](#customization)

ZfrPrerender comes with sane default, but you can customize the module by copying the [`config/zfr_prerender.global.php.dist`](config/zfr_prerender.global.php.dist) file to your `autoload` folder (remove the `.dist` extension), and modify it to suit your needs.

#### Prerender URL

[](#prerender-url)

By default, ZfrPrerender uses the Prerender.io service deployed at `http://service.prerender.io`. However, you may want to [deploy it on your own server](https://github.com/prerender/prerender#deploying-your-own). To that extent, you can customize ZfrPrerender to use your server using the following configuration:

```
return array(
    'zfr_prerender' => array(
        'prerender_url' => 'http://myprerenderservice.com'
    )
);
```

With this config, here is how ZfrPrerender will proxy the "" request:

`GET`

#### Crawler user-agents

[](#crawler-user-agents)

ZfrPrerender decides to pre-render based on the User-Agent string to check if a request comes from a bot or not. By default, those user agents are registered: `baidu`, `facebookexternalhit` and `twitterbot`.

> GoogleBot, Yahoo and BingBot are not in the list starting from ZfrPrerender 2.0 as those search engines support the *escaped\_fragment* approach, and we want to ensure people are not [penalized for cloacking](http://fr.wikipedia.org/wiki/Cloaking).

You can add other User-Agent string to evaluate using this sample configuration:

```
return array(
    'zfr_prerender' => array(
        'crawler_user_agents' => array('yandex', 'msnbot')
    )
);
```

> Note: ZfrPrerender also supports the detection of a crawler through the user of the `_escaped_fragment_` query param. You can learn more about this on [Google's website](https://developers.google.com/webmasters/ajax-crawling/docs/getting-started).

#### Ignored extensions

[](#ignored-extensions)

ZfrPrerender is configured by default to ignore all the requests for resources with those extensions: `.css`, `.gif`, `.jpeg`, `.jpg`, `.js`, `.png`, `.less`, `.pdf`, `.doc`, `.txt`, `.zip`, `.mp3`, `.rar`, `.exe`, `.wmv`, `.doc`, `.avi`, `.ppt`, `.mpg`, `.mpeg`, `.tif`, `.wav`, `.mov`, `.psd`, `.ai`, `.xls`, `.mp4`, `.m4a`, `.swf`, `.dat`, `.dmg`, `.iso`, `.flv`, `.m4v`, `.torrent`. Those are never pre-rendered.

You can add your own extensions using this sample configuration:

```
return array(
    'zfr_prerender' => array(
        'ignored_extensions' => array('.less', '.pdf')
    )
);
```

#### Whitelist

[](#whitelist)

Whitelist a single url path or multiple url paths. Compares using regex, so be specific when possible. If a whitelist is supplied, only url's containing a whitelist path will be prerendered.

Here is a sample configuration that *only* pre-render URLs that contains "/users/":

```
return array(
    'zfr_prerender' => array(
        'whitelist_urls' => array('/users/*')
    )
);
```

> Note: remember to specify URL here and not ZF2 route names. This occur because ZfrPrerender registers a listener that happen very early in the MVC process, before the routing is actually done.

#### Blacklist

[](#blacklist)

Blacklist a single url path or multiple url paths. Compares using regex, so be specific when possible. If a blacklist is supplied, all url's will be pre-rendered except ones containing a blacklist part. Please note that if the referer is part of the blacklist, it won't be pre-rendered too.

Here is a sample configuration that prerender all URLs *excepting* the ones that contains "/users/":

```
return array(
    'zfr_prerender' => array(
        'blacklist_urls' => array('/users/*')
    )
);
```

> Note: remember to specify URL here and not ZF2 route names. This occur because ZfrPrerender registers a listener that happen very early in the MVC process, before the routing is actually done.

### Events

[](#events)

`ZfrPrerender\Mvc\PrerenderListener` triggers two events:

1. `ZfrPrerender\Mvc\PrerenderEvent::EVENT_PRERENDER_PRE`: this event is triggered before actually making the request to Prerender service. If you return a `Zend\Http\Response` object from the listener attached to this event, it will immediately return this response, hence avoiding a new request to the Prerender service.
2. `ZfrPrerender\Mvc\PrerenderEvent::EVENT_PRERENDER_POST`: this event is triggered once the response from the Prerender service is made. This allows you to cache it (for instance in Memcached).

Listeners attached to those two events receive an instance of `ZfrPrerender\Mvc\PrerenderEvent`. Here is an example that shows you how to register listeners using the shared event manager. In your `Module.php` class:

```
use ZfrPrerender\Mvc\PrerenderEvent;

public function onBootstrap(MvcEvent $event)
{
    $eventManager  = $event->getTarget()->getEventManager();
    $sharedManager = $eventManager->getSharedManager();

    $sharedManager->attach(
        'ZfrPrerender\Mvc\PrerenderListener',
        PrerenderEvent::EVENT_PRERENDER_PRE,
        array($this, 'prerenderPre')
    );

    $sharedManager->attach(
        'ZfrPrerender\Mvc\PrerenderListener',
        PrerenderEvent::EVENT_PRERENDER_POST,
        array($this, 'prerenderPost')
    );
}

public function prerenderPre(PrerenderEvent $event)
{
    $request = $event->getRequest();

    // Check from your cache if you have already the content
    // $content = ...

    $response = new Response();
    $response->setStatusCode(200);
    $response->setContent($content);

    return $response;
}

public function prerenderPost(PrerenderEvent $event)
{
    // This is the response we get from the Prerender service
    $response = $event->getResponse();

    // You could get the body and put it in cache
    // ...
}
```

### Testing

[](#testing)

If you want to make sure your pages are rendering correctly:

1. Open the Developer Tools in Chrome (Cmd + Atl + J)
2. Click the Settings gear in the bottom right corner.
3. Click "Overrides" on the left side of the settings panel.
4. Check the "User Agent" checkbox.
5. Choose "Other..." from the User Agent dropdown.
6. Type googlebot into the input box.
7. Refresh the page (make sure to keep the developer tools open).

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 80.7% 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 ~194 days

Recently: every ~425 days

Total

10

Last Release

2850d ago

Major Versions

v1.1.2 → v2.0.02013-11-21

v2.1.0 → v3.0.02014-04-16

PHP version history (2 changes)v1.0.0PHP &gt;=5.3.3

v3.0.0PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e3c74232d02a5fedbcef4650bac1d1103be292d4a013f6f9e692befcc9bb7ca?d=identicon)[bakura10](/maintainers/bakura10)

---

Top Contributors

[![bakura10](https://avatars.githubusercontent.com/u/1198915?v=4)](https://github.com/bakura10 "bakura10 (46 commits)")[![thoop](https://avatars.githubusercontent.com/u/1259374?v=4)](https://github.com/thoop "thoop (4 commits)")[![StyleT](https://avatars.githubusercontent.com/u/1125900?v=4)](https://github.com/StyleT "StyleT (3 commits)")[![Mopolo](https://avatars.githubusercontent.com/u/1319234?v=4)](https://github.com/Mopolo "Mopolo (2 commits)")[![Ocramius](https://avatars.githubusercontent.com/u/154256?v=4)](https://github.com/Ocramius "Ocramius (2 commits)")

---

Tags

prerenderajaxzf2crawlable

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[pubnub/pubnub

This is the official PubNub PHP SDK repository.

1314.6M17](/packages/pubnub-pubnub)[agungsugiarto/codeigniter4-cors

Send CORS Headers in a CodeIgniter 4 application.

6524.6k2](/packages/agungsugiarto-codeigniter4-cors)[evandotpro/edp-github

Github API integration module for Zend Framework 2

241.6k](/packages/evandotpro-edp-github)[narno/gandi-api

Simple PHP library for the Gandi API.

1622.3k](/packages/narno-gandi-api)

PHPackages © 2026

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