-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Injecting Data from Server #1703
Comments
I'm going to tag this for 0.10 just so we don't forget, but if this is unactionable that's fine too. |
How about using try-catch so that we can handle it safely in development? <script>
try {
window.SERVER_DATA = __SERVER_DATA__;
} catch(e) {
console.info('Development MODE', e)
window.SERVER_DATA = {};
}
</script> |
Retagging to clean up 0.10. |
Another idea is to use a script src. E.g. window.SERVER_DATA = {some: 'thing'}; Then the web server doesn't need to do some something like this: # pseudo python server code
def render_homepage(request):
with open('build/index.html') as f:
html = f.read()
html = html.replace('__SERVER_DATA__', "{some: 'thing'};")
return response(html) |
@peterbe I guess you mean a data.js file? I doubt we can load JSON through |
@peterbe Wouldn't that require another request to the server? |
@LeoI11 Be aware that injecting data from the server has a major drawback as it will not allow search engines to properly analyze the static HTML. |
Data injected with proposed <script> tag won't be cached with serviceworker in production and won't be available when offline. My current approach is: index.html <script>
window.APP_BUILD = {
HASH: '__APP_BUILD_HASH__',
}
</script> App.js const buildHash = !window.APP_BUILD.HASH || window.APP_BUILD.HASH === '__APP_BUILD_HASH__'
? undefined
: window.APP_BUILD.HASH |
Our docs explain how to Inject Data from the Server, but this doesn't translate well to development.
I think we should expand the docs to explain what to do in development or add means of specifying these values in development mode.
Right now I just live with the error and do something like this:
This will be annoying for people using this suggested method when the error dialog is merged (if they're currently ignoring the error).
The text was updated successfully, but these errors were encountered: