Skip to content

Commit

Permalink
Add global IS_PRERENDERING
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-dimitru committed Dec 3, 2017
1 parent bf7b73d commit 742b783
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ One service for all modern web applications needs - [Prerendering](https://ostr.
- [Cache purge](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/cache-purge.md)
- [ES6 / ECMAScript 2015 Support](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/es6-support.md)
- [Strip JavaScript](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/strip-javascript.md)
- [Detect Prerendering engine requests during runtime](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/detect-prerendering.md)
- [Detect Prerendering engine requests during runtime (*Meteor specific*)](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/detect-prerendering-meteor.md)

### Monitoring
- __About__: Nowadays website downtime may cause profit loss for any online business, and nearly every business is presented online. It's very important to take an action as soon as possible in event of server, hardware or software failure. We offer proactive monitoring with alerts about occurred issues and issues prediction which may lead to failures in the future.
Expand Down
4 changes: 3 additions & 1 deletion docs/prerendering/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
- [Caching](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/cache.md)
- [Cache purge](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/cache-purge.md)
- [ES6 / ECMAScript 2015 Support](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/es6-support.md)
- [Strip JavaScript](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/strip-javascript.md)
- [Strip JavaScript](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/strip-javascript.md)
- [Detect Prerendering engine requests during runtime](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/detect-prerendering.md)
- [Detect Prerendering engine requests during runtime (*Meteor specific*)](https://github.com/VeliovGroup/ostrio/blob/master/docs/prerendering/detect-prerendering-meteor.md)
23 changes: 23 additions & 0 deletions docs/prerendering/detect-prerendering-meteor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Detect request from Prerendering engine in Meteor.js
======

Prerendering engine will set `window.IS_PRERENDERING` global variable to `true`. As in Meteor everything should be reactive, let's bound it with `ReactiveVar`:

```js
const IS_PRERENDERING = new ReactiveVar(false);
Object.defineProperty(window, 'IS_PRERENDERING', {
set(val) {
IS_PRERENDERING.set(val);
},
get() {
return IS_PRERENDERING.get();
}
});

// Make globally available Blaze helper,
// Feel free to omit this line in case if you're not using Blaze
// or going to handle logic in JavaScript part
Template.registerHelper('IS_PRERENDERING', () => IS_PRERENDERING.get());
```

__Note__: `window.IS_PRERENDERING` might be `undefined` on initial page load, and may change during runtime.
25 changes: 25 additions & 0 deletions docs/prerendering/detect-prerendering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Detect request from Prerendering engine during runtime
======

Prerendering engine will set `window.IS_PRERENDERING` global variable to `true`. Detecting request from prerendering engine might be as easy as:
```js
if (window.IS_PRERENDERING) {
// This request is coming from Prerendering engine
}
```

__Note__: `window.IS_PRERENDERING` might be `undefined` on initial page load, and may change during runtime. That's why we recommend to pre-define a setter for `IS_PRERENDERING`:
```js
let _is_prerendering = false;
Object.defineProperty(window, 'IS_PRERENDERING', {
set(val) {
_is_prerendering = val;
if (_is_prerendering === true) {
// This request is coming from Prerendering engine
}
},
get() {
return _is_prerendering;
}
});
```

0 comments on commit 742b783

Please sign in to comment.