The Cloud Functions for Firebase documentation here states that this can be done using cloud functions –
Prerendering for single page apps to improve SEO. This allows you to create dynamic meta tags for sharing across various social networks.
There are 2 questions I have:
-
Can someone explain with an example how pre-rendering is achieved?
-
How does this work in conjunction with Firebase Hosting? So let’s say I have a webpage at
xyz.com/salon/43
and in Firebase hosting I have a salon.html which is served in response to this request. Now in order to be able to prerender should I move from hosting to a cloud function which renders the webpage? In other words do I go from"rewrites": [{ "source": "/salon/*", "destination": "/salon.html"}]
to
"rewrites": [{ "source": "/salon", "function": "salon"}]
3
Answers
You are correct, you effectively rewrite your app’s HTML page to point to a function instead of a static document. Then, when that page is accessed, your function will effectively generate the HTML that gets sent back to the browser. You are taking this opportunity to decide, at that very moment, what the contents of the HTML should be.
If the contents don’t need to be generated on every single access (each of which costs money according to the billing rates shown on the pricing page), you’ll also probably want to make use of caching to eliminate to serve cached, pre-rendered content from the Firebase Hosting CDNs.
Two tasks:
– Add the function to your hosting rewrite as in your example
– Write the function to generate an html page
This tutorial provides a great example, with the following function as an example from a longer snippet:
First of all, sorry for my poor English.
After searching through Deep Web (joking), I found the solution. And the coolest solution was that I was able to integrate my Pioneer Ionic application with Firebase Hosting using Cloud Functions.
After reading the following topic:
https://github.com/firebase/firebase-tools/issues/33
The @TheRoccoB user explains how to host the static Web application in Firebase Hosting and redirect traffic from a URL to Cloud Functions.
What I did was map the routes that I have to index as:
Since “ssr” is the name of my function in Cloud Functions. So I used the library https://github.com/prerender/prerender-node to check if the request is from a google crowler, in case I redirect the request to a https://github.com/prerender/prerender server.