2017 © Pedro PelĂĄez
 

symfony-bundle prerender-bundle

Allows you to easily use prerender for your Symfony2 apps running Client-Side MVC

image

nick4fake/prerender-bundle

Allows you to easily use prerender for your Symfony2 apps running Client-Side MVC

  • Saturday, December 26, 2015
  • by nick4fake
  • Repository
  • 1 Watchers
  • 0 Stars
  • 62 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 13 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Yucca/PrerenderBundle

Build Status Coverage Status, (*1)

Backbone, EmberJS, Angular and so more are your daily basis ? In case of an admin area, that's fine, but on your front office, you might encounter some SEO problems, (*2)

Thanks to Prerender.io, you now can dynamically render your JavaScript pages in your server using PhantomJS., (*3)

This bundle is largely inspired by bakura10 work on zfr-prerender, (*4)

Installation

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

$ php composer.phar require "yucca/prerender-bundle" "0.1.*@dev"

Register the bundle in app/AppKernel.php:, (*6)

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Yucca\PrerenderBundle\YuccaPrerenderBundle(),
    );
}

Enable the bundle's configuration in app/config/config.yml:, (*7)

# app/config/config.yml
yucca_prerender: ~

Documentation

How it works

  1. Check to make sure we should show a prerendered page
    1. Check if the request is from a crawler (agent string)
    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 (PhantomJS server) for the page's prerendered HTML
  3. Return that HTML to the crawler

Customization

This bundle comes with a sane default, extracted from prerender-node middleware, but you can easily customize it:, (*8)

#app/config/config.yml
yucca_prerender:
    ....

Prerender URL

By default, YuccaPrerenderBundle uses the Prerender.io service deployed at http://prerender.herokuapp.com. However, you may want to deploy it on your own server. To that extent, you can customize YuccaPrerenderBundle to use your server using the following configuration:, (*9)

#app/config/config.yml
yucca_prerender:
    backend_url: http://localhost:3000

With this config, here is how YuccaPrerender will proxy the "https://google.com" request:, (*10)

GET http://localhost:3000/https://google.com, (*11)

Crawler user-agents

YuccaPrerender 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: 'baiduspider', 'facebookexternalhit', 'twitterbot'. Googlebot, Yahoo, and Bingbot should not be in this list because we support escaped_fragment instead of checking user agent for those crawlers. Your site must have to understand the '#!' ajax url notation., (*12)

You can add other User-Agent string to evaluate using this sample configuration:, (*13)

#app/config/config.yml
yucca_prerender:
    crawler_user_agents: ['yandex', 'msnbot']

Ignored extensions

YuccaPrerender is configured by default to ignore all the requests for resources with those extensions: .js, .css, .less, .png, .jpg, .jpeg, .gif, .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., (*14)

You can add your own extensions using this sample configuration:, (*15)

#app/config/config.yml
yucca_prerender:
    ignored_extensions: ['.less', '.pdf']

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., (*16)

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

#app/config/config.yml
yucca_prerender:
    whitelist_urls: ['/users/*']

Note: remember to specify URL here and not Symfony2 route names., (*18)

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., (*19)

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

#app/config/config.yml
yucca_prerender:
    blacklist_urls: ['/users/*']

Note: remember to specify URL here and not Symfony22 route names., (*21)

Testing

If you want to make sure your pages are rendering correctly:, (*22)

  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).

Thanks

  • Thanks to bakura10 for the Zend Framework version.
  • Thanks to Romain Boyer to make me discover prerender.io
  • Thanks to the prerender team and all JS MVC developpers

The Versions

26/12 2015

dev-master

9999999-dev http://rjanot.github.io/

Allows you to easily use prerender for your Symfony2 apps running Client-Side MVC

  Sources   Download

MIT

The Requires

 

The Development Requires

prerender mvc js

20/06 2015

1.3

1.3.0.0 http://rjanot.github.io/

Allows you to easily use prerender for your Symfony2 apps running Client-Side MVC

  Sources   Download

MIT

The Requires

 

The Development Requires

prerender mvc js

28/08 2014

1.2

1.2.0.0 http://rjanot.github.io/

Allows you to easily use prerender for your Symfony2 apps running Client-Side MVC

  Sources   Download

MIT

The Requires

 

The Development Requires

prerender mvc js

27/10 2013

1.1

1.1.0.0 http://rjanot.github.io/

Allows you to easily use prerender for your Symfony2 apps running Client-Side MVC

  Sources   Download

MIT

The Requires

 

The Development Requires

prerender mvc js

13/10 2013

1.0

1.0.0.0 http://rjanot.github.io/

Allows you to easily use prerender for your Symfony2 apps running Client-Side MVC

  Sources   Download

MIT

The Requires

 

The Development Requires

prerender mvc js