Coder Social home page Coder Social logo

rack-prerender's Introduction

Rack::Prerender

Gem Version Build Status

This is a fork and drop-in replacement for prerender_rails with some improvements, most notably improved performance for non-crawlers.

Installation

Add it to your gemfile or run

gem install rack-prerender

Usage

The public interface is fully compatible with prerender_rails, so see its readme.

The middleware class name (Rack::Prerender) and options are the same.

Only additive changes will be made to the interface, see Improvements below.

If you need to require the gem manually: require 'rack/prerender'

Improvements

Better performance for regular users (non-bots)

About 0.07ms instead of 0.5ms lost per request in my case. See benchmark.rb.

Modular structure

You can call the service manually:

  • Rack::Prerender.fetch(my_url) (uses token etc. from middleware setup or ENV)
  • or Rack::Prerender.fetch(my_url, prerender_token: token, ...)
  • you can also pass a Request or env or ActiveRecord/Model to #fetch:
  • Rack::Prerender.fetch(User.last) (assuming there is a route for user)

You can use your own constraint or fetcher:

  • rack_prerender_instance.constraint = MyBotConstraint.new

Recaching / cache-busting functionality:

  • Rack::Prerender.recache_later(my_url) (async, requires ActiveJob or Sidekiq)
  • Rack::Prerender.recache_now(my_url) (sync)
  • both use token from middleware setup or ENV and default API URL, to override:
  • Rack::Prerender.recache_now(my_url, prerender_recache_url: my_api_url, ...)

More options for constraints:

  • you can pass a single Regexp as whitelist or blacklist
  • (prerender_rails supports only a String, or an Array of Strings or Regexps)
  • you can pass Regexp(s) for crawler_user_agents and extensions_to_ignore

Directly works with the param-based URL of the prerender node app:

  • e.g. PRERENDER_SERVICE_URL=https://my-service.com/render?url=

Bugfixes

  • correct Content-Length for compressed pages with multibyte chars
  • removes Transfer-Encoding header after result decompression
  • supports recent (non-vulnerable) versions of Rack
  • works without undeclared dependency activesupport

Contribute

Pull requests and suggestions are welcome.

rack-prerender's People

Contributors

0xradical avatar chris-olszewski avatar edgarv09 avatar fernandes avatar gagalago avatar imanel avatar jaynetics avatar pimlock avatar samuraisam avatar sharshenov avatar thoop avatar wa0x6e avatar waffle-iron avatar

Watchers

 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.