fetch
is native in client-side only and so is not available server-side. Therefore a fetch
that works in both client-side and server-side is recommended.window
object. You should not try to access any of the properties or methods available in the window
object from code that is going to be executed on the server, as the code will fail since the window
object is only available in the browser./home
in the browser's address bar and press Enter, then the page with the slug home
is rendered in the server and served to the client. If we enter the URL /contact
in the browser's address bar and press Enter, then the page with the slug contact
is rendered in the server and served to the client./home
in the browser's address bar and press Enter, and then once the page has loaded in the browser we go to the /contact
URL from a link in the page.home
is rendered in the server and served to the client (as before)contact
is this time rendered in the client and displayed to the userhome
page "server-side Navigation" and the navigation process to get to the contact
page "client-side Navigation"home
page, and a Client-Side Render process (CSR) in the case of the contact
page.refresh
button in the browser on a page that has been rendered in CSR)/home
in the diagram above) Frontity does the following:/contact
in the diagram above):init
actionbeforeSSR
actionafterSSR
actioninit
action (again)beforeCSR
actionafterCSR
actionindex.js
file in the src
folder of the theme package you're using for your Frontity project.index.js
you can have the following two files:client.js
β the entry point of our app when client-side takes controlsserver.js
β the entry point of our app when server-side takes controlsserver.js
one in Node.js and the client.js
one in the browser, and it will ignore the index.js
file - which can, nevertheless, still exist.client.js
and server.js
), or in the default index.js
.beforeSSR
is independent of using a server.js
file. You can add a beforeSSR
function to your index.js
and it works fine. The code, of course, will make it into the client bundle, but the action wonβt be called there (unless you call it manually).client.js
and server.js
files are:"fs"
or "path"
, because they will fail if present in the client bundle ("dot-env"
for accessing environment variables, for example).he
to decode entities in the server.js
, but it weighs in at 73Kbs. You can therefore use new DOMParser().parseFromString
, which is available in the browser and so is essentially free, in the client.js
instead.frontity.settings.js
file is executed at Build Time, this file also has access to server-side packages and environment variables.beforeSSR
action.useEffect
) will also be executed only on the client-side.window
object or the native fetch
inside of the useEffect
hook.init
action of the index.js
file is executed in both the server and the client-side.