# Velo: Improving Page Performance with Manual Caching

Source: https://support.wix.com/en/article/velo-improving-page-performance-with-manual-caching (updated 2022-05-02)
Related: Wix developer documentation, https://dev.wix.com/docs/llms.txt; Help Center index, https://support.wix.com/en/llms.txt

Caching helps to significantly speed up a page’s loading time. Most pages on Wix Sites are cached automatically. However, pages with Velo code or dynamic content may be excluded from automatic caching. In these cases, you can [enable caching manually](https://support.wix.com/en/article/velo-improving-page-performance-with-manual-caching#enable-manual-caching-for-a-page) to get the benefits of faster loading times.

## What is page caching?

When a site visitor requests a page on your site, Wix caches the rendered page to a content delivery network (CDN). The next time someone requests this page, Wix displays the cached version instead of rendering the page’s elements and assets from scratch. There are distinct caches of pages generated for mobile and desktop views of the site. Wix saves page caches for as long as possible. Whenever a Wix app updates data on your site, such as updating the product catalog in Stores, the cache is cleared automatically. The page is cached again the next time a site visitor requests it.

  
 Once a page is cached, it loads much faster than when rendering it from scratch. Therefore, the more pages on your site are cached, the faster your site is for visitors overall.

## Caching limitations for pages with code

Velo code can change a page dynamically by changing site elements, fetching information from external services, or in other ways. These changes need to be rendered by Wix’s servers every time the page is requested, so they aren’t represented in cached versions. Enabling caching for this type of page may result in the wrong data being displayed to site visitors. Because of this, caching is disabled by default for all pages with added code, though you can [enable it manually](https://support.wix.com/en/article/velo-improving-page-performance-with-manual-caching#enable-manual-caching-for-a-page).

  
 Wix analyzes the code on every page to determine if it can be cached without affecting user experience. If the code passes this test, caching on that page is enabled automatically. However, code affects how a page is displayed in complex ways. Because of this, in many cases Wix cannot tell if a page is safe to cache even if it is. For this reason, we recommend that you review all pages on your site with added code, and [enable manual caching](https://support.wix.com/en/article/velo-improving-page-performance-with-manual-caching#enable-manual-caching-for-a-page) whenever possible.

## When should I enable manual caching?

The main factor to consider when deciding about manual caching is whether a page is displayed in significantly different ways to different site visitors. If it is, caching may interfere with your site visitors’ experience.  

  
 Here are some examples of when you should not enable manual caching:

* Pages displaying data that changes frequently, such as exchange rates, stock market details, or weather.

**See an example**

In this example, frontend code on a page fetches exchange rates from an API and displays them in a TextBox element. A cache of this page includes exchange rate data that becomes outdated. Site visitors accessing the cached page see a flicker. This means they first see the exchange rates from the cached page, which then update to the current rates after the code runs.  
  
![](https://d2x3xhvgiqkx42.cloudfront.net/12345678-1234-1234-1234-1234567890ab/11fda387-da5a-430a-ada3-46def885b67f/2022/01/11/2485df5b-a761-4a19-866a-545f4b0983da/791cb8c7-442c-4ba4-9094-c70fcbc825fa.png)

* Pages that customize the display of elements such as currency or time zone based on a site visitor’s geolocation.
* Pages that automatically update date or time.

**See an example**

The code below creates a new JavaScript Date object and stores it in a variable. The code then uses the variable to update the date and time in the page’s footer text.

![](https://d2x3xhvgiqkx42.cloudfront.net/12345678-1234-1234-1234-1234567890ab/11fda387-da5a-430a-ada3-46def885b67f/2022/01/11/894370eb-07c9-4fff-ba0c-a42ebed099bd/89c9fcd1-5306-4cda-968a-4c2075beaeca.png) 

 The value of Date changes constantly, so it presents a caching concern. Wix’s code analysis cannot keep track of everything that happens to a variable’s data. Therefore, if a Date object is assigned to a variable in a page’s code, caching remains disabled for that page.

* Pages that include dynamic content such as member areas, Wix Router pages, or Wix Site Search pages.

If your page doesn’t fit any of these descriptions, you should enable manual caching.

> **Note** If you add code to your site’s masterPage.js file, caching may be disabled for every page on your site. This is because the code in this file runs on every page and can affect how each page is displayed. We recommend checking your masterPage.js file and only including code that must run on every page. Move other code to the appropriate page files.

## Making your code cache-friendly

Here are things you can do to make caching work better on your site:

* **Use the Rendering API**  
If your page code only needs to run in the browser, use the wix-window [Rendering API](https://www.wix.com/velo/reference/wix-window/rendering-obj) to prevent server-side rendering. Formatting your code this way allows Wix to cache the page automatically.

**See an example**

To use the API, wrap your code like this: ![](https://d2x3xhvgiqkx42.cloudfront.net/12345678-1234-1234-1234-1234567890ab/11fda387-da5a-430a-ada3-46def885b67f/2022/01/11/d2c507f9-fce6-48b1-9cb3-e3381c85c236/6811d10e-147a-4ffe-a8e5-858f346bcadc.png)

* **Invalidate the cache manually**  
If your page’s data only updates occasionally, you can still enable manual caching and [invalidate](https://www.wix.com/velo/reference/wix-site-backend/invalidatecache) the cache in your code whenever the data is updated.

## Enable manual caching for a page

1. Go to your Editor.
2. Click **Pages** ![](https://d2x3xhvgiqkx42.cloudfront.net/12345678-1234-1234-1234-1234567890ab/11fda387-da5a-430a-ada3-46def885b67f/2022/01/11/539d0413-4e3c-441b-b31e-301ed952e532/f008b6fa-6268-4813-8d46-edf6ca70e0a7.png).
3. Hover over the relevant page and click **Show More** ![](https://d2x3xhvgiqkx42.cloudfront.net/12345678-1234-1234-1234-1234567890ab/11fda387-da5a-430a-ada3-46def885b67f/2022/01/11/3fcac047-aeeb-408f-8937-6c9c2a810178/db7a6b71-6dd7-4188-9fd4-1be442b7ff58.png).
4. Select **Settings** from the menu.
5. Click **Advanced Settings**.
6. Click the **Manually control caching for this page** toggle. Once you have enabled manual caching, you can choose how often the page’s cache is reset.  
    
![](https://lh3.googleusercontent.com/KRexHxrzG3xOUoLp3NCIMEWzhZ1Q6qE9m9-QjyqZUVkg4pLJeOi1oQcE97PrWWQdcgSNkX23zetK-EUQPSuAuID06-cgQjHjw0RsLcQCx4lOOevH1PkoGoD-p6XYPmMKlhgvjoSh)
