About JavaScript Support

Wix supports working in JavaScript to develop websites, as well as some special features, including:

  • Support for JavaScript features
  • Support for modules
  • Support for the JavaScript Fetch API
  • Sharing JavaScript code naturally between the backend and frontend using web modules

Supported IDEs

You can work in JavaScript in:

  • The editor (Wix Studio and Wix Editor).
  • The Wix IDE (Wix Studio).
  • Your local IDE (Wix Studio and Wix Editor).

JavaScript feature support (ECMAScript 2020)

Wix supports modern JavaScript features up through and including the ES2020 standard.

You can use promises, async/await, and arrow functions, which were introduced with ES2017.

Browsers are gradually adopting the ES2019 standard. Until these standards are fully implemented, we transpile your code into ES5, so it can run in current browsers. Wix supports source maps, so that even though the browser runs transpiled ES5 code, you can debug your ES2019 source code in your browser's developer tools. 

Module support (ECMAScript 2015)

Wix supports the native module functionality included in the ES2015 release of JavaScript.

To use ES2015 module functionality, you need to follow the ES2015 Module Syntax. Only those items specifically exported in a module are exposed to other files. All other items in your module are internal to the module only.

For examples of how to use this functionality, see MDN's JavaScript modules guide.

Notes:

  • You can only export functions in files that are located in the Public or Backend sections of your site's code. You can't export functions from page or popup files.
  • Certain module export formats are not supported in events.js, data.js, or routers.js files. For more information, see Module Export Syntax for Backend Events, Data Hooks, and Routers.

Module scope

The following is a list of guidelines that define how you can share modules and functions between, and within, the backend and public scopes:

  • A JavaScript file or script in backend can import a module from any file in backend or public.
  • A file in public can import a module from any file in public.
  • You can import functions from backend and use them in public, using a web module.
  • You can use relative paths to refer to files with the "." prefix.
  • You can import a module from backend with the backend/ prefix.
  • You can import a module from public with the public/ prefix.
  • Modules can import other modules.

Wix Fetch

Wix Fetch is an implementation of the standard JavaScript Fetch API, and you work with it the same way, using standard Fetch syntax. You can look at examples of using Fetch, or check out the Standard Fetch specification.

Use Wix Fetch rather than the standard JavaScript Fetch API whenever you need an http/s request. You can use Wix Fetch in both backend and frontend code. To use Wix Fetch in your JavaScript code, add import {fetch} from 'wix-fetch' to the beginning of your JavaScript file.

Among its benefits, Wix Fetch uses promises to handle asynchronous requests, which allows for easier handling of results and errors.

See also

Did this help?