Coder Social home page Coder Social logo

oc-prerender-plugin's Introduction

oc-prerender-plugin

License

Single page applications provide a great user experience, but are notorious for their poor SEO. This plugin bridges that gap by integrating October with prerender.io. This allows websites like Google, Facebook, and Twitter to crawl your website perfectly, without sacrificing the experience of a SPA.

Installation

Install the plugin by running the following commands from your root October directory

git clone [email protected]:scottbedard/oc-prerender-plugin.git plugins/bedard/prerender

composer update

Next, configure your prerender token by adding the following to your .env file

PRERENDER_TOKEN=yoursecrettoken

If you are using a self-hosted service, add the server address to your .env file

PRERENDER_URL=http://example.com

You can disable the service by adding the following to your .env file

PRERENDER_ENABLE=false

Recaching pages

This plugin exposes a bedard.prerender.recache event that can be used to recache URLs. For example, say you want to recache blog posts when the content is changes. You could add the following to your Plugin.php file achieve this.

public function boot()
{
    \RainLab\Blog\Models\Post::extend(function ($model) {
        $model->bindEvent('afterSave', function () use ($model) {
            \Event::fire('bedard.prerender.recache', 'https://example.com/blog/' . $model->slug);
        });
    });
}

Customizing

Prerendering can be customized by adding the following to a configuration file at config/bedard/prerender/config.php. Check the October documentation for information on setting environment specific configuration. Click here to see the default configuration.

Whitelist

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.

'whitelist' => [
    '/frontend/*' // only prerender pages starting with '/frontend/'
]

Blacklist

If a blacklist is supplied, all url's will be prerendered except ones containing a blacklist path. By default, a set of asset extensions are included. Note that this is the full request URI, so including starting slash and query parameter string.

'blacklist' => [
    '/api/*' // do not prerender pages starting with '/api/'
]

User Agents

Requests from crawlers that do not support _escaped_fragment_ will nevertheless be served with prerendered pages. You can customize the list of crawlers using the following config entry.

'crawler_user_agents' => [
    'googlebot',
]

FAQ

Do I need prerendering?

If you're writing traditional themes using October's AJAX framework, then probably not. This plugin is designed for themes like Vuetober, where the majority of rendering is done on the client side.

Isn't this what SSR is for?

Yes, but server-rendered applications bring with them a lot of baggage. For starters they often require a Node server, complicated build steps, and that you write "universal code". Prerendering achieves many of the benefits of SSR, with significantly fewer moving parts.

How can I verify the integration is working?

Start by checking out the prerender.io testing docs. To see how your site looks to different crawlers, try changing your user agent to something like "Googlebot". Click here to learn how to do this in Chrome.

Credit

Many thanks to jeroennoten for providing the middleware used in this plugin.

License

MIT

oc-prerender-plugin's People

Contributors

scottbedard avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.