prerender_rails 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -46
- data/lib/prerender_rails.rb +1 -1
- data/prerender_rails.gemspec +1 -1
- data/test/lib/prerender_rails.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecf7a38c64f481c20b394e6bc5044eff1233395e
|
4
|
+
data.tar.gz: c0308f0a13f9dbb3d551ffa55de2bdbe30249537
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dccc5aac455510547500c0c271fa45ad0ff5e0fc3a551a91c60e4db29524cbe2da91199983b406bec0af9753fca1b96126b9b104aabea8565d97c8f80c899896
|
7
|
+
data.tar.gz: 95804e50b88d5571d4cf8429789599b405eb89d6b637ebaa034dc3168e562fb058f965f865ea4512ac4993cc7b6f37d78da8c46e28a0a8128b1f3e97cd03305c
|
data/README.md
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
Prerender Rails [![Build Status](https://travis-ci.org/collectiveip/prerender_rails.png)](https://travis-ci.org/collectiveip/prerender_rails) [![Gem Version](https://badge.fury.io/rb/prerender_rails.png)](http://badge.fury.io/rb/prerender_rails)
|
2
2
|
===========================
|
3
3
|
|
4
|
-
|
4
|
+
Google, Facebook, Twitter, Yahoo, and Bing are constantly trying to view your website... but they don't execute javascript. That's why we built Prerender. Prerender is perfect for AngularJS SEO, BackboneJS SEO, EmberJS SEO, and any other javascript framework.
|
5
5
|
|
6
|
-
|
6
|
+
This middleware intercepts requests to your Rails website from crawlers, and then makes a call to the (external) Prerender Service to get the static HTML instead of the javascript for that page.
|
7
7
|
|
8
|
-
`
|
8
|
+
Prerender adheres to google's `_escaped_fragment_` proposal, which we recommend you use. It's easy:
|
9
|
+
- Just add <meta name="fragment" content="!"> to the <head> of all of your pages
|
10
|
+
- If you use hash urls (#), change them to the hash-bang (#!)
|
11
|
+
- That's it! Perfect SEO on javascript pages.
|
9
12
|
|
10
|
-
|
11
|
-
* Make sure you have more than one webserver thread/process running because the prerender service will make a request to your server to render the HTML.
|
12
|
-
* If you're testing on localhost, you need to run the prerender server locally so that it can access your server.
|
13
|
+
`Note` Make sure you have more than one webserver thread/process running because the prerender service will make a request to your server to render the HTML.
|
13
14
|
|
14
15
|
Add this line to your application's Gemfile:
|
15
16
|
|
@@ -27,39 +28,30 @@ or if you have an account on [prerender.io](http://prerender.io) and want to use
|
|
27
28
|
config.middleware.use Rack::Prerender, prerender_token: 'YOUR_TOKEN'
|
28
29
|
```
|
29
30
|
|
30
|
-
|
31
|
-
1. Check to make sure we should show a prerendered page
|
32
|
-
1. Check if the request is from a crawler (`_escaped_fragment_` or agent string)
|
33
|
-
2. Check to make sure we aren't requesting a resource (js, css, etc...)
|
34
|
-
3. (optional) Check to make sure the url is in the whitelist
|
35
|
-
4. (optional) Check to make sure the url isn't in the blacklist
|
36
|
-
2. Make a `GET` request to the [prerender service](https://github.com/collectiveip/prerender)(phantomjs server) for the page's prerendered HTML
|
37
|
-
3. Return that HTML to the crawler
|
38
|
-
|
31
|
+
`Note` If you're testing locally, you'll need to run the [prerender server](https://github.com/collectiveip/prerender) locally so that it has access to your server.
|
39
32
|
|
40
|
-
##
|
33
|
+
## Testing
|
41
34
|
|
42
|
-
|
35
|
+
If your URLs use a hash-bang:
|
43
36
|
|
44
|
-
|
37
|
+
If you want to see `http://localhost:5000/#!/profiles/1234`
|
38
|
+
Then go to `http://localhost:5000/?_escaped_fragment_=/profiles/1234`
|
45
39
|
|
46
|
-
|
40
|
+
If your URLs use push-state:
|
47
41
|
|
48
|
-
|
42
|
+
If you want to see `http://localhost:5000/profiles/1234`
|
43
|
+
Then go to `http://localhost:5000/profiles/1234?_escaped_fragment_=`
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@redis.set(Rack::Request.new(env).url, response.body)
|
59
|
-
end)
|
60
|
-
```
|
45
|
+
## How it works
|
46
|
+
1. The middleware checks to make sure we should show a prerendered page
|
47
|
+
1. The middleware checks if the request is from a crawler (`_escaped_fragment_` or agent string)
|
48
|
+
2. The middleware checks to make sure we aren't requesting a resource (js, css, etc...)
|
49
|
+
3. (optional) The middleware checks to make sure the url is in the whitelist
|
50
|
+
4. (optional) The middleware checks to make sure the url isn't in the blacklist
|
51
|
+
2. The middleware makes a `GET` request to the [prerender service](https://github.com/collectiveip/prerender)(phantomjs server) for the page's prerendered HTML
|
52
|
+
3. Return that HTML to the crawler
|
61
53
|
|
62
|
-
|
54
|
+
# Customization
|
63
55
|
|
64
56
|
### Whitelist
|
65
57
|
|
@@ -112,9 +104,31 @@ config.middleware.use Rack::Prerender,
|
|
112
104
|
end)
|
113
105
|
```
|
114
106
|
|
107
|
+
## Caching
|
108
|
+
|
109
|
+
This rails middleware is ready to be used with [redis](http://redis.io/) or [memcached](http://memcached.org/) to return prerendered pages in milliseconds.
|
110
|
+
|
111
|
+
When setting up the middleware in `config/environment/production.rb`, you can add a `before_render` method and `after_render` method for caching.
|
112
|
+
|
113
|
+
Here's an example testing a local redis cache:
|
114
|
+
|
115
|
+
_Put this in `config/environment/development.rb`, and add `gem 'redis'` to your Gemfile._
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
require 'redis'
|
119
|
+
@redis = Redis.new
|
120
|
+
config.middleware.use Rack::Prerender,
|
121
|
+
before_render: (Proc.new do |env|
|
122
|
+
@redis.get(Rack::Request.new(env).url)
|
123
|
+
end),
|
124
|
+
after_render: (Proc.new do |env, response|
|
125
|
+
@redis.set(Rack::Request.new(env).url, response.body)
|
126
|
+
end)
|
127
|
+
```
|
128
|
+
|
115
129
|
## Using your own prerender service
|
116
130
|
|
117
|
-
|
131
|
+
We host a Prerender server at [prerender.io](http://prerender.io) so that you can work on more important things, but if you've deployed the prerender service on your own... set the `PRERENDER_SERVICE_URL` environment variable so that this middleware points there instead. Otherwise, it will default to the service already deployed by [prerender.io](http://prerender.io).
|
118
132
|
|
119
133
|
$ export PRERENDER_SERVICE_URL=<new url>
|
120
134
|
|
@@ -125,21 +139,9 @@ Or on heroku:
|
|
125
139
|
As an alternative, you can pass `prerender_service_url` in the options object during initialization of the middleware
|
126
140
|
|
127
141
|
``` ruby
|
128
|
-
config.middleware.use Rack::Prerender, prerender_service_url: '
|
142
|
+
config.middleware.use Rack::Prerender, prerender_service_url: '<new url>'
|
129
143
|
```
|
130
144
|
|
131
|
-
## Testing
|
132
|
-
|
133
|
-
If you want to make sure your pages are rendering correctly:
|
134
|
-
|
135
|
-
1. Open the Developer Tools in Chrome (Cmd + Atl + J)
|
136
|
-
2. Click the Settings gear in the bottom right corner.
|
137
|
-
3. Click "Overrides" on the left side of the settings panel.
|
138
|
-
4. Check the "User Agent" checkbox.
|
139
|
-
6. Choose "Other..." from the User Agent dropdown.
|
140
|
-
7. Type `googlebot` into the input box.
|
141
|
-
8. Refresh the page (make sure to keep the developer tools open).
|
142
|
-
|
143
145
|
## License
|
144
146
|
|
145
147
|
The MIT License (MIT)
|
data/lib/prerender_rails.rb
CHANGED
@@ -153,7 +153,7 @@ module Rack
|
|
153
153
|
|
154
154
|
|
155
155
|
def get_prerender_service_url
|
156
|
-
@options[:prerender_service_url] || ENV['PRERENDER_SERVICE_URL'] || 'http://prerender.
|
156
|
+
@options[:prerender_service_url] || ENV['PRERENDER_SERVICE_URL'] || 'http://service.prerender.io/'
|
157
157
|
end
|
158
158
|
|
159
159
|
|
data/prerender_rails.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "prerender_rails"
|
5
|
-
spec.version = "0.1.
|
5
|
+
spec.version = "0.1.14"
|
6
6
|
spec.authors = ["Todd Hooper"]
|
7
7
|
spec.email = ["todd@collectiveip.com"]
|
8
8
|
spec.description = %q{Rails middleware to prerender your javascript heavy pages on the fly by a phantomjs service}
|
data/test/lib/prerender_rails.rb
CHANGED
@@ -139,7 +139,7 @@ describe Rack::Prerender do
|
|
139
139
|
it "should build the correct api url with the default url" do
|
140
140
|
request = Rack::MockRequest.env_for "https://google.com/search?q=javascript"
|
141
141
|
ENV['PRERENDER_SERVICE_URL'] = nil
|
142
|
-
assert_equal 'http://prerender.
|
142
|
+
assert_equal 'http://service.prerender.io/https://google.com/search?q=javascript', @prerender.build_api_url(request)
|
143
143
|
end
|
144
144
|
|
145
145
|
|
@@ -162,7 +162,7 @@ describe Rack::Prerender do
|
|
162
162
|
it "should build the correct api url for the Cloudflare Flexible SSL support" do
|
163
163
|
request = Rack::MockRequest.env_for "http://google.com/search?q=javascript", { 'CF-VISITOR' => '"scheme":"https"'}
|
164
164
|
ENV['PRERENDER_SERVICE_URL'] = nil
|
165
|
-
assert_equal 'http://prerender.
|
165
|
+
assert_equal 'http://service.prerender.io/https://google.com/search?q=javascript', @prerender.build_api_url(request)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prerender_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Hooper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|