Move injecting data from the server into the page into its own file

This commit is contained in:
Kristofer Selbekk
2018-10-07 20:07:28 +02:00
parent 2ddff8b468
commit 328ac7bedf
3 changed files with 20 additions and 20 deletions

View File

@@ -0,0 +1,17 @@
---
id: injecting-data-from-the-server-into-the-page
title: Injecting Data from the Server into the Page
---
Similarly to the previous section, you can leave some placeholders in the HTML that inject global variables, for example:
```js
<!doctype html>
<html lang="en">
<head>
<script>
window.SERVER_DATA = __SERVER_DATA__;
</script>
```
Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data right before sending the response. The client code can then read `window.SERVER_DATA` to use it. **Make sure to [sanitize the JSON before sending it to the client](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0) as it makes your app vulnerable to XSS attacks.**

View File

@@ -11,7 +11,6 @@ You can find the most recent version of this guide [here](https://github.com/fac
## Table of Contents
- [Injecting Data from the Server into the Page](#injecting-data-from-the-server-into-the-page)
- [Making a Progressive Web App](#making-a-progressive-web-app)
- [Why Opt-in?](#why-opt-in)
- [Offline-First Considerations](#offline-first-considerations)
@@ -19,21 +18,6 @@ You can find the most recent version of this guide [here](https://github.com/fac
- [Advanced Configuration](#advanced-configuration)
- [Alternatives to Ejecting](#alternatives-to-ejecting)
## Injecting Data from the Server into the Page
Similarly to the previous section, you can leave some placeholders in the HTML that inject global variables, for example:
```js
<!doctype html>
<html lang="en">
<head>
<script>
window.SERVER_DATA = __SERVER_DATA__;
</script>
```
Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data right before sending the response. The client code can then read `window.SERVER_DATA` to use it. **Make sure to [sanitize the JSON before sending it to the client](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0) as it makes your app vulnerable to XSS attacks.**
## Making a Progressive Web App
The production build has all the tools necessary to generate a first-class

View File

@@ -33,11 +33,13 @@
"adding-relay",
"adding-a-router",
"adding-custom-environment-variables",
"can-i-use-decorators",
"fetching-data-with-ajax-requests",
"integrating-with-an-api-backend",
"using-https-in-development",
"generating-dynamic-meta-tags-on-the-server",
"pre-rendering-into-static-html-files"
"pre-rendering-into-static-html-files",
"injecting-data-from-the-server-into-the-page"
],
"Testing": ["running-tests", "debugging-tests"],
"Deployment": ["publishing-components-to-npm", "deployment"],
@@ -46,9 +48,6 @@
"updating-to-new-releases",
"sending-feedback",
"something-missing"
],
"Frequently Asked Questions": [
"can-i-use-decorators"
]
}
}