seo_cache 0.16.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/pull_request_template.md +14 -0
- data/.rubocop.yml +16 -43
- data/.travis.yml +39 -5
- data/CHANGELOG.md +23 -0
- data/CODE_OF_CONDUCT.md +11 -9
- data/CONTRIBUTING.md +21 -24
- data/README.md +68 -22
- data/lib/seo_cache.rb +3 -0
- data/lib/seo_cache/middleware.rb +8 -2
- data/lib/seo_cache/page_render.rb +2 -0
- data/lib/seo_cache/populate_cache.rb +6 -5
- data/lib/seo_cache/version.rb +1 -1
- data/seo_cache.gemspec +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ee9a26729de232dd3907da2de2af951a5e911b4e4232de92859ca99fa43b0e5
|
4
|
+
data.tar.gz: 2e156bc6455e91f2b401c48091c942e10b6ed8f3565982caa587a48409090df7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a67455edd4979de42d1ab769cc6dd3001c5ef65c5d453f7f10ab2dc566004ebd33967fafe02f3ce4ce50c8507b7eb811931a20812bb2c532101556e508fa4d8
|
7
|
+
data.tar.gz: 56fb3ebc4e5dc8d5e40374445f11c49e0c048f2db5f30eeaaebac66388d62a0f59711d2f08c1050469a89727df1cef57792698551037cc28db6f099fd539522e
|
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
A clear and concise description of what the bug is.
|
12
|
+
|
13
|
+
**To Reproduce**
|
14
|
+
Steps to reproduce the behavior:
|
15
|
+
1. Go to '...'
|
16
|
+
2. Click on '....'
|
17
|
+
3. Scroll down to '....'
|
18
|
+
4. See error
|
19
|
+
|
20
|
+
**Expected behavior**
|
21
|
+
A clear and concise description of what you expected to happen.
|
22
|
+
|
23
|
+
**Screenshots**
|
24
|
+
If applicable, add screenshots to help explain your problem.
|
25
|
+
|
26
|
+
**Desktop (please complete the following information):**
|
27
|
+
- OS: [e.g. iOS]
|
28
|
+
- Browser [e.g. chrome, safari]
|
29
|
+
- Version [e.g. 22]
|
30
|
+
|
31
|
+
**Smartphone (please complete the following information):**
|
32
|
+
- Device: [e.g. iPhone6]
|
33
|
+
- OS: [e.g. iOS8.1]
|
34
|
+
- Browser [e.g. stock browser, safari]
|
35
|
+
- Version [e.g. 22]
|
36
|
+
|
37
|
+
**Additional context**
|
38
|
+
Add any other context about the problem here.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
12
|
+
|
13
|
+
**Describe the solution you'd like**
|
14
|
+
A clear and concise description of what you want to happen.
|
15
|
+
|
16
|
+
**Describe alternatives you've considered**
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
18
|
+
|
19
|
+
**Additional context**
|
20
|
+
Add any other context or screenshots about the feature request here.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
### Summary
|
2
|
+
|
3
|
+
Provide a general description of the code changes in your pull
|
4
|
+
request... were there any bugs you had fixed? If so, mention them. If
|
5
|
+
these bugs have open GitHub issues, be sure to tag them here as well,
|
6
|
+
to keep the conversation linked together.
|
7
|
+
|
8
|
+
### Other Information
|
9
|
+
|
10
|
+
If there's anything else that's important and relevant to your pull
|
11
|
+
request, mention that information here. This could include
|
12
|
+
benchmarks, or other information.
|
13
|
+
|
14
|
+
Thanks for contributing to SeoCache!
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
+
# Documentation
|
2
|
+
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
|
3
|
+
# http://rubocop.readthedocs.io/en/latest
|
4
|
+
|
1
5
|
AllCops:
|
2
6
|
TargetRubyVersion: 2.6
|
3
7
|
|
4
|
-
|
8
|
+
Bundler/OrderedGems:
|
5
9
|
Enabled: false
|
6
10
|
|
7
|
-
|
11
|
+
Layout/HashAlignment:
|
8
12
|
Enabled: false
|
9
13
|
|
10
|
-
|
14
|
+
Layout/ParameterAlignment:
|
11
15
|
Enabled: false
|
12
16
|
|
13
17
|
Layout/CaseIndentation:
|
@@ -16,6 +20,9 @@ Layout/CaseIndentation:
|
|
16
20
|
Layout/CommentIndentation:
|
17
21
|
Enabled: false
|
18
22
|
|
23
|
+
Layout/EmptyLinesAroundBlockBody:
|
24
|
+
Enabled: false
|
25
|
+
|
19
26
|
Layout/EmptyLinesAroundClassBody:
|
20
27
|
Enabled: false
|
21
28
|
|
@@ -35,9 +42,6 @@ Layout/FirstArrayElementIndentation:
|
|
35
42
|
Layout/FirstHashElementIndentation:
|
36
43
|
Enabled: false
|
37
44
|
|
38
|
-
Layout/HashAlignment:
|
39
|
-
Enabled: false
|
40
|
-
|
41
45
|
Layout/LeadingCommentSpace:
|
42
46
|
Enabled: false
|
43
47
|
|
@@ -53,9 +57,6 @@ Layout/MultilineMethodCallIndentation:
|
|
53
57
|
Layout/MultilineOperationIndentation:
|
54
58
|
Enabled: false
|
55
59
|
|
56
|
-
Layout/ParameterAlignment:
|
57
|
-
Enabled: false
|
58
|
-
|
59
60
|
Layout/SpaceAroundOperators:
|
60
61
|
Enabled: false
|
61
62
|
|
@@ -89,47 +90,16 @@ Metrics/MethodLength:
|
|
89
90
|
CountComments: false # count full line comments?
|
90
91
|
Max: 120
|
91
92
|
|
92
|
-
Metrics/ModuleLength:
|
93
|
-
CountComments: false # count full line comments?
|
94
|
-
Max: 350
|
95
|
-
|
96
|
-
Metrics/ParameterLists:
|
97
|
-
Max: 7
|
98
|
-
|
99
93
|
Metrics/PerceivedComplexity:
|
100
94
|
Enabled: false
|
101
95
|
|
102
96
|
Naming/RescuedExceptionsVariableName:
|
103
97
|
Enabled: false
|
104
98
|
|
105
|
-
|
106
|
-
Enabled: false
|
107
|
-
|
108
|
-
Rails/FindBy:
|
109
|
-
Enabled: false
|
110
|
-
|
111
|
-
Rails/HasAndBelongsToMany:
|
112
|
-
Enabled: false
|
113
|
-
|
114
|
-
Rails/HelperInstanceVariable:
|
115
|
-
Enabled: false
|
116
|
-
|
117
|
-
Rails/OutputSafety:
|
118
|
-
Enabled: false
|
119
|
-
|
120
|
-
Rails/UnknownEnv:
|
121
|
-
Enabled: false
|
122
|
-
|
123
|
-
Rails/Validation:
|
99
|
+
Style/AsciiComments:
|
124
100
|
Enabled: false
|
125
101
|
|
126
|
-
|
127
|
-
Max: 20
|
128
|
-
|
129
|
-
RSpec/MultipleExpectations:
|
130
|
-
Max: 10
|
131
|
-
|
132
|
-
Style/AsciiComments:
|
102
|
+
Style/BlockDelimiters:
|
133
103
|
Enabled: false
|
134
104
|
|
135
105
|
Style/ClassAndModuleChildren:
|
@@ -141,7 +111,10 @@ Style/ColonMethodCall:
|
|
141
111
|
Style/CommandLiteral:
|
142
112
|
Enabled: false
|
143
113
|
|
144
|
-
Style/
|
114
|
+
Style/DoubleNegation:
|
115
|
+
Enabled: false
|
116
|
+
|
117
|
+
Style/GlobalVars:
|
145
118
|
Enabled: false
|
146
119
|
|
147
120
|
Style/Lambda:
|
data/.travis.yml
CHANGED
@@ -1,7 +1,41 @@
|
|
1
1
|
---
|
2
|
-
sudo: false
|
3
2
|
language: ruby
|
4
|
-
|
5
|
-
|
6
|
-
-
|
7
|
-
|
3
|
+
|
4
|
+
gemfile:
|
5
|
+
- Gemfile
|
6
|
+
|
7
|
+
before_install:
|
8
|
+
- gem update --system -N
|
9
|
+
- gem install bundler -N
|
10
|
+
|
11
|
+
services:
|
12
|
+
- redis
|
13
|
+
|
14
|
+
addons:
|
15
|
+
apt:
|
16
|
+
packages:
|
17
|
+
- chromium-browser
|
18
|
+
|
19
|
+
cache:
|
20
|
+
bundler: true
|
21
|
+
directories:
|
22
|
+
- ~/.webdrivers
|
23
|
+
|
24
|
+
notifications:
|
25
|
+
email:
|
26
|
+
on_success: never
|
27
|
+
on_failure: change
|
28
|
+
|
29
|
+
script: bundle exec rake $RAKE_TASK
|
30
|
+
|
31
|
+
matrix:
|
32
|
+
include:
|
33
|
+
- rvm: 2.7
|
34
|
+
gemfile: Gemfile
|
35
|
+
env: RAKE_TASK=spec
|
36
|
+
- rvm: 2.6
|
37
|
+
gemfile: Gemfile
|
38
|
+
env: RAKE_TASK=spec
|
39
|
+
- rvm: 2.5
|
40
|
+
gemfile: Gemfile
|
41
|
+
env: RAKE_TASK=spec
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
## 1.0.1
|
2
|
+
|
3
|
+
- Add user agent to missed caches
|
4
|
+
|
5
|
+
## 1.0.0
|
6
|
+
|
7
|
+
- Update Readme (badges, syntax, links, ...)
|
8
|
+
- Add Travis CI
|
9
|
+
- Update dependencies
|
10
|
+
- Do not cache pages in error
|
11
|
+
|
12
|
+
## 0.19.0
|
13
|
+
|
14
|
+
- Add option to cache page if user connected
|
15
|
+
|
16
|
+
## 0.18.0
|
17
|
+
|
18
|
+
- Correct use of prerender param in URL
|
19
|
+
|
20
|
+
## 0.17.0
|
21
|
+
|
22
|
+
- Correct bug when populating cache
|
23
|
+
|
1
24
|
## 0.16.0
|
2
25
|
|
3
26
|
- Add prerender params when populating cache
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
In the interest of fostering an open and welcoming environment, we as
|
6
6
|
contributors and maintainers pledge to making participation in our project and
|
7
7
|
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression,
|
9
|
-
|
10
|
-
orientation.
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
11
|
|
12
12
|
## Our Standards
|
13
13
|
|
@@ -23,13 +23,13 @@ include:
|
|
23
23
|
Examples of unacceptable behavior by participants include:
|
24
24
|
|
25
25
|
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
26
|
+
advances
|
27
27
|
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
28
|
* Public or private harassment
|
29
29
|
* Publishing others' private information, such as a physical or electronic
|
30
|
-
|
30
|
+
address, without explicit permission
|
31
31
|
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
|
32
|
+
professional setting
|
33
33
|
|
34
34
|
## Our Responsibilities
|
35
35
|
|
@@ -68,7 +68,9 @@ members of the project's leadership.
|
|
68
68
|
## Attribution
|
69
69
|
|
70
70
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
72
|
|
73
|
-
[homepage]:
|
74
|
-
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
74
|
+
|
75
|
+
For answers to common questions about this code of conduct, see
|
76
|
+
https://www.contributor-covenant.org/faq
|
data/CONTRIBUTING.md
CHANGED
@@ -1,41 +1,38 @@
|
|
1
|
-
|
1
|
+
## How to contribute to Ruby on Rails
|
2
2
|
|
3
|
-
|
3
|
+
#### **Did you find a bug?**
|
4
4
|
|
5
|
-
|
5
|
+
* **Do not open up a GitHub issue if the bug is a security vulnerability**, and instead to contact us by email contact@ginkonote.com.
|
6
6
|
|
7
|
-
|
7
|
+
* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/floXcoder/seo_cache/issues).
|
8
8
|
|
9
|
-
|
9
|
+
* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/floXcoder/seo_cache/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **scenario** demonstrating the expected behavior that is not occurring.
|
10
10
|
|
11
|
-
|
11
|
+
* If possible, use the relevant bug report templates to create the issue:
|
12
|
+
* [**Bug** issues](https://github.com/floXcoder/seo_cache/blob/develop/.github/ISSUE_TEMPLATE/bug_report.md)*
|
13
|
+
|
14
|
+
#### **Did you have an idea to improve the project?**
|
12
15
|
|
13
|
-
|
16
|
+
* Open a new GitHub issue request with your idea.
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
* If possible, use the relevant feature report templates to create the issue:
|
19
|
+
* [**Feature** issues](https://github.com/floXcoder/seo_cache/blob/develop/.github/ISSUE_TEMPLATE/feature_request.md)
|
17
20
|
|
18
|
-
|
19
|
-
gem "seo_cache", github: "floXcode/seo_cache"
|
20
|
-
```
|
21
|
+
#### **Did you write a patch that fixes a bug or do you intend to add a new feature or change an existing one?**
|
21
22
|
|
22
|
-
|
23
|
+
* Fork the project, write your code and open a new GitHub pull request with the patch.
|
23
24
|
|
24
|
-
|
25
|
-
- Complete backtraces for exceptions
|
25
|
+
* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
|
26
26
|
|
27
|
-
|
27
|
+
* If possible, use the relevant pull request report templates to create the issue:
|
28
|
+
* [**Pull Request**](https://github.com/floXcoder/seo_cache/blob/develop/.github/pull_request_template.md)
|
29
|
+
|
30
|
+
#### **Do you have questions about the source code?**
|
28
31
|
|
29
|
-
|
32
|
+
* You can contact me by email: flo@l-x.fr. I will try to answer as much I can and if available.
|
30
33
|
|
31
|
-
## Pull Requests
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
- Keep changes to a minimum. If you have multiple features or fixes, submit multiple pull requests.
|
36
|
-
- Follow the existing style. The code should read like it’s written by a single person.
|
37
|
-
|
38
|
-
Feel free to open an issue to get feedback on your idea before spending too much time on it.
|
35
|
+
Thanks!
|
39
36
|
|
40
37
|
---
|
41
38
|
|
data/README.md
CHANGED
@@ -1,14 +1,34 @@
|
|
1
1
|
# SeoCache
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/seo_cache.svg)](https://badge.fury.io/rb/seo_cache)
|
4
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
|
5
|
+
[![Build Status](https://travis-ci.org/floXcoder/seo_cache.svg)](https://travis-ci.org/floXcoder/seo_cache)
|
6
|
+
|
7
|
+
**SeoCache is a dedicated cache for SEO with JavaScript rendering** :fire:
|
8
|
+
|
9
|
+
You can find in this article, a more detail explanation of the purpose and usage of this gem:
|
10
|
+
|
11
|
+
- In english: https://www.ginkonote.com/users/flo/articles/seo-generate-and-cache-your-pages@seo
|
12
|
+
- In french: https://www.ginkonote.com/fr/utilisateurs/flo/articles/seo-generation-et-mise-en-cache-des-pages@seo
|
13
|
+
|
14
|
+
## Table of contents
|
15
|
+
- [Purpose](#purpose)
|
16
|
+
- [Installation](#installation)
|
17
|
+
- [Configuration](#configuration)
|
18
|
+
- [Helpers for controllers](#helpers-for-controllers)
|
19
|
+
- [Check cached pages](#check-cached-pages)
|
20
|
+
- [Automatic caching](#automatic-caching)
|
21
|
+
- [Server configuration](#server-configuration)
|
22
|
+
- [Inspiration](#inspiration)
|
23
|
+
- [Contributing](#contributing)
|
4
24
|
|
5
25
|
## Purpose
|
6
26
|
|
7
27
|
Google credo is: Don't waste my bot time!
|
8
28
|
|
9
|
-
|
29
|
+
In order to reduce Googlebot crawling time, let's provide the complete HTML files in a specific cache.
|
10
30
|
|
11
|
-
This cache is suitable for static (generated or not) pages but not for
|
31
|
+
This cache is suitable for static (generated or not) pages but not for user private pages.
|
12
32
|
|
13
33
|
## Installation
|
14
34
|
|
@@ -38,7 +58,7 @@ require 'seo_cache'
|
|
38
58
|
Rails.application.config.middleware.use SeoCache::Middleware
|
39
59
|
```
|
40
60
|
|
41
|
-
##
|
61
|
+
## Configuration
|
42
62
|
|
43
63
|
Chrome path (**required**) (`disk` or `memory`):
|
44
64
|
|
@@ -97,13 +117,13 @@ SeoCache.whitelist_hosts = []
|
|
97
117
|
URLs to blacklist:
|
98
118
|
|
99
119
|
```ruby
|
100
|
-
SeoCache.
|
120
|
+
SeoCache.blacklist_urls = %w[^/assets/.* ^/admin.*]
|
101
121
|
```
|
102
122
|
|
103
123
|
Params to blacklist:
|
104
124
|
|
105
125
|
```ruby
|
106
|
-
SeoCache.
|
126
|
+
SeoCache.blacklist_params = %w[page]
|
107
127
|
```
|
108
128
|
|
109
129
|
URLs to whitelist:
|
@@ -112,6 +132,12 @@ URLs to whitelist:
|
|
112
132
|
SeoCache.whitelist_urls = []
|
113
133
|
```
|
114
134
|
|
135
|
+
Cache page even if user is connected (be careful when caching sensitive data):
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
SeoCache.cache_with_user_connected = true
|
139
|
+
```
|
140
|
+
|
115
141
|
Parameter to add manually to the URl to force page caching, if you want to cache a specific URL (e.g. `https://<my_website>/?_seo_cache_=true`):
|
116
142
|
|
117
143
|
```ruby
|
@@ -148,28 +174,36 @@ If you encounter the following error `DevToolsActivePort file doesn't exist`, yo
|
|
148
174
|
SeoCache.chrome_debugging_port = '9222'
|
149
175
|
```
|
150
176
|
|
151
|
-
Be aware, JS will be rendered twice: once by
|
177
|
+
Be aware, JS will be rendered twice: once by this gem and once by client. For React, this not a problem but with jQuery plugins, it can duplicate elements in the page (you have to check the redundancy).
|
152
178
|
|
153
|
-
Disk cache is recommended by default. Nginx will directly fetch
|
179
|
+
Disk cache is recommended by default. Nginx will directly fetch HTML files on disk. The TTFB (time to first byte) will be under 200ms :). You can use memory cache if you have lot of RAM, but if you shut down your server, you will lost all the generated pages! So prefer cache disk storage.
|
154
180
|
|
155
|
-
##
|
181
|
+
## Helpers for controllers
|
156
182
|
|
157
183
|
You can check if seo mode is active in your controllers, with the following variable:
|
158
184
|
|
159
185
|
```ruby
|
160
|
-
|
186
|
+
def check_seo_mode
|
187
|
+
@seo_mode = (params.key?(SeoCache.prerender_url_param) || params.key?(SeoCache.force_cache_url_param))
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
191
|
+
And if you want to access to this variable in JS files:
|
192
|
+
|
193
|
+
```javascript
|
194
|
+
window.seoMode = "{@seo_mode}"
|
161
195
|
```
|
162
196
|
|
163
197
|
|
164
|
-
##
|
198
|
+
## Check cached pages
|
165
199
|
|
166
|
-
Too see in browser the
|
200
|
+
Too see in browser the cached page, open a browser and set the user agent to:
|
167
201
|
|
168
202
|
`Googlebot (Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html))`
|
169
203
|
|
170
|
-
For instance, with Chrome or Chromium, you can change the user agent in "Network conditions" panel.
|
204
|
+
For instance, with Chrome or Chromium, you can change the user agent in "Network" / "Network conditions" panel.
|
171
205
|
|
172
|
-
To (re)cache a page, add this parameter to the url (the browser must use the Googlebot user agent):
|
206
|
+
To (re)cache a page, add this parameter to the url (and the browser must use the Googlebot user agent):
|
173
207
|
|
174
208
|
`/?_seo_cache_=true`
|
175
209
|
|
@@ -178,7 +212,7 @@ To (re)cache a page, add this parameter to the url (the browser must use the Goo
|
|
178
212
|
To automate caching, create a cron rake task (e.g. in `lib/tasks/populate_seo_cache.rake`):
|
179
213
|
|
180
214
|
```ruby
|
181
|
-
namespace :
|
215
|
+
namespace :my_project do
|
182
216
|
|
183
217
|
desc 'Populate cache for SEO'
|
184
218
|
task populate_seo_cache: :environment do |_task, _args|
|
@@ -191,14 +225,14 @@ namespace :MyProject do
|
|
191
225
|
end
|
192
226
|
```
|
193
227
|
|
194
|
-
You can add the `force_cache: true` option to `SeoCache::PopulateCache` for overwrite
|
228
|
+
You can add the `force_cache: true` option to `SeoCache::PopulateCache` for overwrite cached data.
|
195
229
|
|
196
|
-
If you want to
|
230
|
+
If you want to execute only through a rake task, you can comment the line which include the middleware. keep all options configured and remove only the middleware. Thus all pages will be cached and SeoCache isn't called for pages not in cache.
|
197
231
|
It's useful if you have a script which generates all website pages (based on sitemap for instance) and you run script every day.
|
198
232
|
|
199
|
-
## Server
|
233
|
+
## Server configuration
|
200
234
|
|
201
|
-
If you use disk caching, add to your Nginx configuration:
|
235
|
+
If you use disk caching, add this to your Nginx configuration:
|
202
236
|
|
203
237
|
```nginx
|
204
238
|
# Before any block:
|
@@ -236,20 +270,32 @@ location / {
|
|
236
270
|
if ($arg__seo_cache_) {
|
237
271
|
break;
|
238
272
|
}
|
273
|
+
|
274
|
+
# Local rewrite to remove trailing slash
|
275
|
+
rewrite ^/(.*)/$ /$1 last;
|
239
276
|
|
240
277
|
try_files /seo_cache/$uri/index$cache_extension /seo_cache/$uri$cache_extension /seo_cache/$uri $uri @rubyproxy;
|
241
278
|
}
|
242
279
|
|
243
280
|
location @rubyproxy {
|
244
|
-
|
281
|
+
proxy_connect_timeout 600;
|
282
|
+
proxy_send_timeout 600;
|
283
|
+
proxy_read_timeout 600;
|
284
|
+
send_timeout 600;
|
285
|
+
proxy_set_header Host $host;
|
286
|
+
proxy_set_header X-Real-IP $remote_addr;
|
287
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
288
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
289
|
+
proxy_pass_header Server;
|
290
|
+
proxy_pass http://0.0.0.0:3020;
|
245
291
|
}
|
246
292
|
```
|
247
293
|
|
248
|
-
This configuration allow you to use SEO cache only for bots (you can add other bots) and GET requests. For users, you don't want to use the cached page (user connection, basket, ...). The performance are less important for users
|
294
|
+
This configuration allow you to use SEO cache only for bots (you can add other bots at the beginning of the file) and HTML GET requests. For connected users, you don't want to use the cached page (user connection, basket, ...). The performance are less important for users than bots.
|
249
295
|
|
250
296
|
## Heroku case
|
251
297
|
|
252
|
-
If you use Heroku server, you can't store
|
298
|
+
If you use Heroku server, you can't store files on dynos. But you have two alternatives:
|
253
299
|
|
254
300
|
- Use the memory mode
|
255
301
|
|
data/lib/seo_cache.rb
CHANGED
data/lib/seo_cache/middleware.rb
CHANGED
@@ -21,7 +21,10 @@ module SeoCache
|
|
21
21
|
|
22
22
|
return cached_response.finish if cached_response.present?
|
23
23
|
|
24
|
-
|
24
|
+
if SeoCache.log_missed_cache
|
25
|
+
env_request = Rack::Request.new(env)
|
26
|
+
SeoCache.log("missed cache : #{env_request.path} (User agent: #{env_request.user_agent})")
|
27
|
+
end
|
25
28
|
|
26
29
|
if SeoCache.prerender_service_url.present?
|
27
30
|
prerender_response = prerender_service(env)
|
@@ -78,6 +81,9 @@ module SeoCache
|
|
78
81
|
request = Rack::Request.new(env)
|
79
82
|
query_params = Rack::Utils.parse_query(request.query_string)
|
80
83
|
|
84
|
+
# Check if user connected
|
85
|
+
return false if !SeoCache.cache_with_user_connected && (env['warden'].respond_to?(:user) && env['warden'].user.present?)
|
86
|
+
|
81
87
|
# If it is the generated page...don't prerender
|
82
88
|
return false if query_params.has_key?(SeoCache.prerender_url_param)
|
83
89
|
|
@@ -188,7 +194,7 @@ module SeoCache
|
|
188
194
|
def page_render(env)
|
189
195
|
# Add key parameter to url
|
190
196
|
request = Rack::Request.new(env)
|
191
|
-
url = if request.query_string.present? || request.url.
|
197
|
+
url = if request.query_string.present? || request.url.include?('?')
|
192
198
|
request.url + '&'
|
193
199
|
else
|
194
200
|
request.url + '?'
|
@@ -6,9 +6,9 @@ require 'seo_cache/page_render'
|
|
6
6
|
module SeoCache
|
7
7
|
class PopulateCache
|
8
8
|
def initialize(host, paths, options = {})
|
9
|
-
@host
|
10
|
-
@paths
|
11
|
-
@page_render
|
9
|
+
@host = host
|
10
|
+
@paths = paths
|
11
|
+
@page_render = PageRender.new
|
12
12
|
@page_caching = PageCaching.new
|
13
13
|
|
14
14
|
@force_cache = options.fetch(:force_cache, false)
|
@@ -19,7 +19,7 @@ module SeoCache
|
|
19
19
|
next if @page_caching.cache_exists?(path) && !@force_cache
|
20
20
|
|
21
21
|
url = @host + path
|
22
|
-
url += if path.
|
22
|
+
url += if path.include?('?')
|
23
23
|
'&'
|
24
24
|
else
|
25
25
|
'?'
|
@@ -27,9 +27,10 @@ module SeoCache
|
|
27
27
|
url += "#{SeoCache.prerender_url_param}=true"
|
28
28
|
|
29
29
|
page_source = @page_render.get(url, false)
|
30
|
-
@page_caching.cache(page_source, path)
|
30
|
+
@page_caching.cache(page_source, path) if page_source
|
31
31
|
end
|
32
32
|
|
33
|
+
ensure
|
33
34
|
@page_render.close_connection
|
34
35
|
end
|
35
36
|
end
|
data/lib/seo_cache/version.rb
CHANGED
data/seo_cache.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_dependency 'selenium-webdriver', '~> 3'
|
29
29
|
spec.add_dependency 'webdrivers', '~> 4'
|
30
30
|
|
31
|
-
spec.add_development_dependency 'bundler', '~>
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
32
32
|
spec.add_development_dependency 'rake', '~> 13'
|
33
33
|
spec.add_development_dependency 'rspec', '~> 3'
|
34
34
|
spec.add_development_dependency 'simplecov', '~> 0.17'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seo_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FloXcoder
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '2'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '2'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rake
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,6 +186,9 @@ executables: []
|
|
186
186
|
extensions: []
|
187
187
|
extra_rdoc_files: []
|
188
188
|
files:
|
189
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
190
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
191
|
+
- ".github/pull_request_template.md"
|
189
192
|
- ".gitignore"
|
190
193
|
- ".rspec"
|
191
194
|
- ".rubocop.yml"
|
@@ -226,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
229
|
- !ruby/object:Gem::Version
|
227
230
|
version: '0'
|
228
231
|
requirements: []
|
229
|
-
rubygems_version: 3.
|
232
|
+
rubygems_version: 3.0.8
|
230
233
|
signing_key:
|
231
234
|
specification_version: 4
|
232
235
|
summary: Cache dedicated for SEO with Javascript rendering
|