env
Gets the current environment the rendering process is running in.
Description
When possible, the rendering process is split in two in order to improve performance. The first cycle in the process happens in the server-side code and the second cycle happens in the client-side code. If not possible on the server-side, all rendering happens client-side.
The env
property returns "backend"
when rendering on the server
and "browser"
when rendering on the client.
Use the env
property in your page's onReady()
event handler to control where your code runs during the rendering
process and to prevent code that causes side effects from running twice.
Note: Rendering never occurs server-side when previewing your site.
Type:
Was this helpful?
Use the Rendering API to avoid inserting an item twice
This example demonstrates how to make sure a collection insertion in the onReady
event handler occurs only once.
1import wixData from 'wix-data';2import wixWindowFrontend from 'wix-window-frontend';34let toInsert = {5 "field1": "Some value",6 "field2": "Some other value"7};89$w.onReady(function () {10 if (wixWindowFrontend.rendering.env === "browser") {11 return wixData.insert("myCollection", toInsert)12 .then( (item) => {13 $w("#myText").text = item.title;14 } );15 }16} );17