• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    Java
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

java framework for prerender

Prerender Java

Are you using backbone, angular, emberjs, etc, but you're unsure about the SEO implications?

Use this java filter that prerenders a javascript-rendered page using an external service and returns the HTML to the search engine crawler for SEO.

Note: If you are using a # in your urls, make sure to change it to #!. View Google's ajax crawling protocol

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.

1:Add this line to your web.xml:

<filter>
      <filter-name>prerender</filter-name>
      <filter-class>com.github.greengerong.PreRenderSEOFilter</filter-class>
      <init-param>
          <param-name>prerenderToken</param-name>
          <param-value>[get from prerender: https://prerender.io/]</param-value>
      </init-param>
  </filter>
  <filter-mapping>
      <filter-name>prerender</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>

2:add dependency on your project pom:

<dependency>
  <groupId>com.github.greengerong</groupId>
  <artifactId>prerender-java</artifactId>
  <version>1.6.4</version>
</dependency>

How it works

  1. Check to make sure we should show a prerendered page
    1. Check if the request is from a crawler (_escaped_fragment_ or 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

crawlerUserAgents

example: someproxy,someproxy1

whitelist

blacklist

forwardedURLHeader

Important for servers behind reverse proxy that need the public url to be used for pre-rendering. We usually set the original url in an http header which is added by the reverse proxy (similar to the more standard x-forwarded-proto and x-forwarded-for)

protocol

If you specifically want to make sure that the Prerender service queries using https or http protocol, you can set the init-param protocol to https or http respectively.

Using your own prerender service

If you've deployed the prerender service on your own, set the PRERENDER_SERVICE_URL environment variable so that this package points there instead. Otherwise, it will default to the service already deployed at http://service.prerender.io/

$ export PRERENDER_SERVICE_URL=<new url>

Or on heroku:

$ heroku config:add PRERENDER_SERVICE_URL=<new url>

As an alternative, you can pass prerender_service_url in the options object during initialization of the middleware

 config filter init param with "prerenderServiceUrl";

prerender service token

If you want to use token with the prerender service, you can config it.

 config filter init param with "prerenderToken";

prerender event handler

If you want to cache the caching, analytics, log or others, you can config it. It should be instance of "com.github.greengerong.PreRenderEventHandler"

 config filter init param with "preRenderEventHandler";

Testing

If your URLs use a hash-bang:

If you want to see `http://localhost:3000/#!/profiles/1234`
Then go to `http://localhost:3000/?_escaped_fragment_=/profiles/1234`

If your URLs use push-state:

If you want to see `http://localhost:3000/profiles/1234`
Then go to `http://localhost:3000/profiles/1234?_escaped_fragment_=`

project demo test url:

http://localhost:8080/test/?_escaped_fragment_=

License

The MIT License (MIT)

More Repositories

1

rebirth

GreenGerong(破狼) blog with Angular4.
TypeScript
356
star
2

rebirth-ng

rebirth-ng is a ui framework for Angular & bootstrap.
CSS
116
star
3

Prerender_asp_mvc

Prerende client for asp.net mvc
C#
85
star
4

ngmodel-format

format for ng-model.
JavaScript
42
star
5

guice-demo

Java
38
star
6

green.inputmask4angular

JavaScript
30
star
7

rebirth-ionic2

Rebirth blog for Ionic 3
CSS
21
star
8

awesome-llm

Jupyter Notebook
14
star
9

green-auth

auth for angualr request and emit response status to rootscope
JavaScript
12
star
10

angular-ie-enhancer

JavaScript
12
star
11

rebirth-permission

TypeScript
11
star
12

maven-archetypes-demo

It is a demo for maven archetypes plugin. We can use archetypes to generate our project structs.
Python
10
star
13

agile-dashboard

agile-dashboard is a dashboard for project status, like jira, jenkins,sonar,monitor... and so on.
JavaScript
9
star
14

rebirth-admin

Rebirth admin system: Open source of angular seed
TypeScript
8
star
15

Prerender_asp_mvc_demo

C#
7
star
16

opencsv-utils

opencsv-utils
Java
7
star
17

rebirth-storage

TypeScript storage module(memory, sessionStorage, localStorage) and @Cacheable decorator
TypeScript
7
star
18

maven-ng-protractor

maven plugins for angular protractor
Java
6
star
19

rebirth-echarts

rebirth
CSS
6
star
20

node-jquery-demo

demo for node js jquery plugin
JavaScript
6
star
21

SonarLanguage

Sonar project Language pie chart,code by angularjs
JavaScript
6
star
22

rebirth-nativescript

rebirth nativescript version
CSS
5
star
23

greengerong.github.com

破狼博客
HTML
4
star
24

edge-demo

demo for edge with node.js and C#
JavaScript
4
star
25

green-monitor

monitor for depend service
JavaScript
4
star
26

cnblogs-blogs2markdown

JavaScript
3
star
27

rebirth-event-source

ng2 event source by rxjs stream.
JavaScript
3
star
28

prerender-java-redis

Java
3
star
29

Angularjs-node-demo

Angularjs-node-demo
JavaScript
2
star
30

JsTestDriverCoverageReport

javascript coverage report,it can generate html report by google JSTestDriver file
Java
2
star
31

rebirth-model

generate typescript model from json or json schema
JavaScript
2
star
32

qing

JavaScript
2
star
33

soap-parse

Java
2
star
34

socketio-proxy

Change WebSocket connection to http change for old web server which can not work with socket
JavaScript
2
star
35

rebirth-chart

Angular4 chart lib with chart.js
CSS
2
star
36

spring-boot-quartz

Java
2
star
37

build-microservices-with-spring-cloud

Java
2
star
38

cctray-sound

sound for cctray monitor
2
star
39

toggle

HTML
2
star
40

grunt-cs-compile

1
star
41

jenkins-plugin-demo

Java
1
star
42

toggle-angular

TypeScript
1
star
43

aop-handler

Java
1
star
44

common-utils

Java
1
star
45

pages

JavaScript
1
star
46

green-security4angular

Java
1
star
47

ss-ipsec-componse

JavaScript
1
star
48

apollo-client

Groovy
1
star
49

jenkins-slave

1
star
50

kotlin-blog

Kotlin
1
star
51

rebirth-medium-editor

CSS
1
star
52

jenkins-collector-client

Java
1
star
53

devops-build

Groovy
1
star
54

grunt-cs-xunit

JavaScript
1
star
55

ng-pipeline-chart

TypeScript
1
star
56

ng-spike-demo

TypeScript
1
star
57

vital-signs

vital-signs
JavaScript
1
star
58

normal-spike

Java
1
star