# We're Getting Faster: Learn How to Get Your Site Ready

**URL:** <https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327>\
**Category:** Show and tell\
**Tags:** tips, code, wix-stores\
**Created:** [February 21, 2018, 7:31am UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327 "2018-02-21T07:31:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoav-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yoav-wix/32/674_2.png) [@yoav-wix](https://forum.wixstudio.com/u/yoav-wix)\
**Post date:** [February 21, 2018, 7:31am UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/1 "2018-02-21T07:31:42Z")

</div>

We’re excited to announce that, starting soon, your sites will start loading faster in certain circumstances, thanks to the magic of server-side rendering.

Now that your code may run on the server or the browser, there are a few things you might want to know, and some changes which are important to understand.

When server-side rendering is used, your site’s pages will load faster. In most cases you won’t have to do anything at all to take advantage of the increased performance. You can, however, leverage the new Rendering API to further improve your site’s loading time. To learn more about what server-side rendering is and how to harness its power, see [About the Page Rendering Process](https://support.wix.com/en/article/about-the-page-rendering-process) .

# **Important**

When server-side rendering is used, some of your code will run twice, once server-side and once client-side. Although the code runs twice, the end result is still a faster load because the server is able to do all of the heavy lifting that takes longer when done on the client. However, this may change the behavior of your existing code. Read below to understand when this affects your site and what you can do to restore your desired behavior.

# **Rollout**

Server-side rendering will be rolled out in two parts.

1. Beginning today, you will be able to use the new Rendering API. However, sites will still not use server-side rendering.

2. Two weeks from now we will begin rendering sites server-side.  
Use the time between now and **11 March** to get your site ready for server-side rendering if needed.

# **What you need to do**

# 

There are some situations where your current onReady() or global code will cease to work as expected.  
These include:

- Code that causes a side effect.

- Code that must be run in the browser.  
Here are three common examples of where your code might break and what you need to do for your code to work properly with server-side rendering.

**Adding collection data from onReady() or global code**

Problem: If you add data to your collection in your onReady event handler or in your page’s global code, that data will be added twice when server-side rendering is used.

Reason: Your onReady and global code run twice when server-side rendering is used. The data is added to your collection each time the code runs.

Solution: Use the renderCycle property of the Rendering API to make sure the data is only added the first time your code runs.

In the example below, the insert() call is wrapped in an if() that checks which render cycle is being run. The insertion will only occur during the first render cycle. If there is a second render cycle because server-side rendering is being used, the item will not be inserted a second time.

```javascript
import wixData from 'wix-data';
import wixWindow from 'wix-window';

let toInsert = {
 "field1": "Some value",
 "field2": "Some other value"
};

$w.onReady(function () {
  if (wixWindow.rendering.renderCycle === 1) {
  return wixData.insert("myCollection", toInsert)
    .then(item => { 
      $w("#myText").text = item.title; 
    });
});

```

Retrieving storage data from onReady() or global code

Problem: If you try to retrieve data using wix-storage and use that data to populate a page element, the page will flicker when server-side rendering is used.

Reason: The data you’re trying to retrieve is stored in the user’s browser. When you try to retrieve it on the server, it isn’t there. So the element is populated with empty data during the server-side rendering. This is displayed on the screen for a moment before the client-side rendering replaces the empty data with the data retrieved from the client’s browser.

Solution: Use the env property of the Rendering API to make sure the data is only retrieved when your code is run in the browser.

In the example below, the getItem() function is wrapped in an if() that checks which environment the code is being run in. The retrieval will only occur when rendering client-side. If there was also a server-side render, no storage retrieval would have been attempted.

```javascript
import {local} from 'wix-storage';
import wixWindow from 'wix-window';

$w.onReady(function () {
 if (wixWindow.rendering.env === "browser") {
    $w("#myText").text = local.getItem("key"); 
 }
} );

```

Using 3rd party analytics to track site events from onReady or global code

Problem: If you send analytics events to a 3rd part app, two events will be sent when server-side rendering is used.

Reason: Your onReady and global code run twice when server-side rendering is used. The the analytics event is sent each time the code runs.

Solution: Use the renderCycle property of the Rendering API to make sure the event is only sent when rendering in the browser.

In the example below, the trackEvent() call is wrapped in an if() that checks which environment the code is being run in. The event will only be sent when rendering client-side. If there was also a server-side render, an event would not have been sent.

```javascript
import wixWindow from 'wix-window';

$w.onReady(function () {
 if(wixWindow.rendering.env === "browser") {
    wixWindow.trackEvent("ViewContent", {
      id: "P12345",
      name: "Really Fast Running Shoes",
      category: "Apparel/Shoes",
      price: 120,
      currency: "USD",
      brand: "Adidas",
      variant: "Black",
      position: 1
    } );
  }
} );

```

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [February 21, 2018, 7:36am UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/2 "2018-02-21T07:36:26Z")

</div>

\<3

---

<div class="post-metadata">

**Author:** ![daniel-laera](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@daniel-laera](https://forum.wixstudio.com/u/daniel-laera)\
**Post date:** [February 21, 2018, 8:59am UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/3 "2018-02-21T08:59:37Z")

</div>

excellent

---

<div class="post-metadata">

**Author:** ![RobertHamilton](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roberthamilton/32/80382_2.png) [@RobertHamilton](https://forum.wixstudio.com/u/RobertHamilton)\
**Post date:** [February 21, 2018, 1:44pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/4 "2018-02-21T13:44:14Z")

</div>

I’ve got a question. Even if code is not being used, will sites in general load faster? Is this for mobile and desktop also.

---

<div class="post-metadata">

**Author:** ![pavel-schwindt](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/pavel-schwindt/32/2133_2.png) [@pavel-schwindt](https://forum.wixstudio.com/u/pavel-schwindt)\
**Post date:** [February 21, 2018, 5:00pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/5 "2018-02-21T17:00:36Z")

</div>

Wix is the future

---

<div class="post-metadata">

**Author:** ![ivan-terechin](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/ivan-terechin/32/1190_2.png) [@ivan-terechin](https://forum.wixstudio.com/u/ivan-terechin)\
**Post date:** [February 21, 2018, 7:31pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/6 "2018-02-21T19:31:30Z")

</div>

Hi Yoav,  
can you please update

> **[Velo Tutorial: Building Your Own Members Area | Help Center | Wix.com](https://support.wix.com/en/article/velo-tutorial-building-your-own-members-area)**
>
> Visit the Velo by Wix website to onboard and continue learning.Note:You can now add a members area to your site without using code. You can also create a page t

in new rendering condition.  
Thank you very much!!!

---

<div class="post-metadata">

**Author:** ![felipe-bustos](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/felipe-bustos/32/692_2.png) [@felipe-bustos](https://forum.wixstudio.com/u/felipe-bustos)\
**Post date:** [February 21, 2018, 8:47pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/7 "2018-02-21T20:47:32Z")

</div>

This is great! Wix Rules B-)

---

<div class="post-metadata">

**Author:** ![andluism](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andluism/32/789_2.png) [@andluism](https://forum.wixstudio.com/u/andluism)\
**Post date:** [February 22, 2018, 9:47am UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/8 "2018-02-22T09:47:24Z")

</div>

So basically this rendering code is needed in a page that interacts with database right?

How about this statement in one of the article provided here: “For example, if you call the expand() function in your page’s onReady() event handler to display an image that was set in the Editor to be collapsed on load, the expand() might be called twice. The first time expand() is called it will expand the image. The second time it is called it won’t do anything.”

Will running the expand code twice slowing down page load? Should that need to be configured as well?

---

<div class="post-metadata">

**Author:** ![let-s-start-design](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/let-s-start-design/32/686_2.png) [@let-s-start-design](https://forum.wixstudio.com/u/let-s-start-design)\
**Post date:** [February 22, 2018, 4:15pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/9 "2018-02-22T16:15:27Z")

</div>

Can we clarify that if we have code on the sites with forms, databases and dynamic pages, interactions, we need to go back and add some extra code to make sure it works. You mention "These include:

- Code that causes a side effect.

- Code that must be run in the browser."  
Do the cases above fall under these two categories? Sorry just want to make sure I’m ready…

---

<div class="post-metadata">

**Author:** ![andreas-kviby](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andreas-kviby/32/790_2.png) [@andreas-kviby](https://forum.wixstudio.com/u/andreas-kviby)\
**Post date:** [February 25, 2018, 5:17pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/10 "2018-02-25T17:17:01Z")

</div>

So all code that needs to run in the clients browser like redirects, use of local storage, cookies and also all kinds of GEO functions must be inside wixWindow.rendering.env === “browser” to make sure it is executed on the browser and not the server.

Also all kinds of actions that will actually insert or do something should be inside wixWindow.rendering.renderCycle === 1 so we make sure it is executed only once and not twice.

So if we use these two things we will be all good I guess?

---

<div class="post-metadata">

**Author:** ![webmaster-1](https://avatars.discourse-cdn.com/v4/letter/w/58956e/32.png) [@webmaster-1](https://forum.wixstudio.com/u/webmaster-1)\
**Post date:** [February 26, 2018, 9:14pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/11 "2018-02-26T21:14:42Z")

</div>

WOW - so glad I stumbled upon this post. Will have to make a lot of changes.

I want to get it right so I’m going to second Ivan Terechin’s request to update  
[https://support.wix.com/en/article/how-to-create-member-profile-pages-with-wix-code](https://support.wix.com/en/article/how-to-create-member-profile-pages-with-wix-code)  
to reflect the rendering logic.

---

<div class="post-metadata">

**Author:** ![yoav-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yoav-wix/32/674_2.png) [@yoav-wix](https://forum.wixstudio.com/u/yoav-wix)\
**Post date:** [February 28, 2018, 1:21pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/12 "2018-02-28T13:21:28Z")

</div>

andluism,

You only need to worry if you call your database in the $w.onReady function, or before that as part of the global script scope.

As for expand running twice - the impact is minimal, as one runs on the server, one on the client.

---

<div class="post-metadata">

**Author:** ![yoav-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yoav-wix/32/674_2.png) [@yoav-wix](https://forum.wixstudio.com/u/yoav-wix)\
**Post date:** [February 28, 2018, 1:23pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/13 "2018-02-28T13:23:47Z")

</div>

lorraine,

In most cases you need not do anything. This include (the safe category)

- Data Binding

- Dynamic Pages

- Forms

- Any Event handler

- Any code in $w.onReady that only uses $w APIs

---

<div class="post-metadata">

**Author:** ![yoav-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yoav-wix/32/674_2.png) [@yoav-wix](https://forum.wixstudio.com/u/yoav-wix)\
**Post date:** [February 28, 2018, 1:25pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/14 "2018-02-28T13:25:14Z")

</div>

Hay Andreas,

You are right.

But also note that any event handler (e.g. onClick) only runs on the client, as no one will click a button on the server.

---

<div class="post-metadata">

**Author:** ![araiki-technology](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/araiki-technology/32/1766_2.png) [@araiki-technology](https://forum.wixstudio.com/u/araiki-technology)\
**Post date:** [March 1, 2018, 7:10pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/15 "2018-03-01T19:10:37Z")

</div>

wix need to improve loading time on any network any computer my site loading slow and heavy

---

<div class="post-metadata">

**Author:** ![custom-saddles](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/custom-saddles/32/2312_2.png) [@custom-saddles](https://forum.wixstudio.com/u/custom-saddles)\
**Post date:** [March 3, 2018, 2:04am UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/16 "2018-03-03T02:04:39Z")

</div>

I had decided to move away from Wix due to site loading times. So needless to say, Will my photo gallery’s load faster now? Will I be able to upload better quality images and not have to sacrifice load time?

---

<div class="post-metadata">

**Author:** ![\_anno](https://avatars.discourse-cdn.com/v4/letter/_/b3f665/32.png) [@\_anno](https://forum.wixstudio.com/u/_anno)\
**Post date:** [March 6, 2018, 12:10pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/17 "2018-03-06T12:10:26Z")

</div>

Hi,  
My Plant Library site (domain www.theplantlibrary.co.za) (site name the-plant-li) looks terrible on small/ mobile screens as the text and image galleries overlap, and it looks as though each gallery is added twice. Perfect on a desktop. I’m trying to work out if and where to add the suggested code. My page codes look like this:

**imp** ort {local} from “wix-storage”;  
const linkField = “link-Plants-title”;

$w.onReady(function () {  
setUrls(‘#grasslandTrees’, ‘trees’);  
setUrls(‘#grasslandShrubs’, ‘shrubs’);  
setUrls(‘#grasslandPerennials’, ‘perennials’);  
setUrls(‘#grasslandSucculents’, ‘succulents’);  
setUrls(‘#grasslandGroundcovers’, ‘groundcovers’);  
setUrls(‘#grasslandBulbs’, ‘bulbs’);  
setUrls(‘#grasslandGrass’, ‘grass’);  
});

function setUrls(datasetSelector, galleryCategory) {  
$w(datasetSelector).onReady(() =\> {  
const numberOfItems = $w(datasetSelector).getTotalCount();  
$w(datasetSelector).getItems(0, numberOfItems)  
.then( (result) =\> {  
const plantsTitle = result.items.map(item =\> item[linkField]);  
local.setItem(galleryCategory, plantsTitle);  
})  
.catch( (err) =\> {  
console.log(err.code, err.message);  
});  
});  
}

export function trees\_click() {  
local.setItem(‘selected-gallery’, ‘trees’);  
}  
export function shrubs\_click() {  
local.setItem(‘selected-gallery’, ‘shrubs’);  
}  
export function perennials\_click() {  
local.setItem(‘selected-gallery’, ‘perennials’);  
}  
export function succulents\_click() {  
local.setItem(‘selected-gallery’, ‘succulents’);  
}  
export function groundcovers\_click() {  
local.setItem(‘selected-gallery’, ‘groundcovers’);  
}  
export function bulbs\_click() {  
local.setItem(‘selected-gallery’, ‘bulbs’);  
}  
export function grass\_click() {  
local.setItem(‘selected-gallery’, ‘grass’);  
}

**So do** I add your code below? If so, where, and what do I replace the #myText with?

import {local} from ‘wix-storage’;

import wixWindow from ‘wix-window’;

$w.onReady( function () {

if (wixWindow.rendering.env === “browser”) {

$w(" [#myText](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23myText) ").text = local.getItem(“key”);  
}

} );  
}

---

<div class="post-metadata">

**Author:** ![omid-symmetra](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/omid-symmetra/32/710_2.png) [@omid-symmetra](https://forum.wixstudio.com/u/omid-symmetra)\
**Post date:** [March 10, 2018, 2:40pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/18 "2018-03-10T14:40:16Z")

</div>

Those of you wondering about **SPEED IMPROVEMENTS** ought to read my experience

> **[Test Your Wix Code Site with Server-Side Rendering | Velo by Wix](https://community.wix.com/velo/forum/wix-tips-and-updates/test-your-wix-code-site-with-server-side-rendering)**
>
> A little while ago, we announced that starting soon, your Wix Code sites will start loading faster in certain circumstances, thanks to the magic of server-side rendering. (Sites that do not contain code are already rendered on the server when viewed...

---

<div class="post-metadata">

**Author:** ![jonathan-loake](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jonathan-loake/32/2460_2.png) [@jonathan-loake](https://forum.wixstudio.com/u/jonathan-loake)\
**Post date:** [March 11, 2018, 8:35pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/19 "2018-03-11T20:35:47Z")

</div>

Has this gone live now? I’m not seeing any difference in load time.

---

<div class="post-metadata">

**Author:** ![david-seroy](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/david-seroy/32/868_2.png) [@david-seroy](https://forum.wixstudio.com/u/david-seroy)\
**Post date:** [March 11, 2018, 9:51pm UTC](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327/20 "2018-03-11T21:51:48Z")

</div>

I don’t think it’s live yet? I tried making some basic code with an if statement, that runs only on the backend and nothing happens. Maybe we had until today to update it and it goes into effect tomorrow?

```javascript
if wixWindow.rendering.env === 'backend' {
**test code**
} 

```

[Next page](https://forum.wixstudio.com/t/were-getting-faster-learn-how-to-get-your-site-ready/29327.md?page=2)
