Web modules are backend files that allow you to write backend functions that you can easily call from the frontend.
Use web modules for calling backend code from the frontend:
Web modules cannot be used to export primitive values or objects that you want to import on the frontend.
You can create web modules using:
To expose a function within a web module so that it can be called from the frontend, you need to wrap it in a web method. Web methods provide the mechanism that allows your function to be called asynchronously from the frontend and adds a permissions check on the caller of your function.
Here is what a web method looks like when defined in the backend and called from the frontend:
1
1
When you import a web method on the frontend, you get a proxy function to the web method. This proxy uses an XMLHttpRequest to invoke the function in the backend. The runtime listens to those invocations and calls the appropriate function.
The arguments and return value are serialized and deserialized using JSON.
Because web modules expose your site's backend functionality, it's important to restrict who can call web methods from the frontend. Do this by setting the permissions for each web method to be as restrictive as possible.
It is especially important to set restrictive permissions when:
elevation
.The permissions options are:
You can debug the code in web modules as you would debug any backend code. Additionally, you can use console.log()
in your web methods and the logs will appear in the Developer Console when previewing your site. For security reasons, the logs will not appear in your browser's console when previewing or on your published site.
.jsw
web modulesWeb modules were originally created using .jsw
files. This method for creating web modules is now deprecated. However, existing .jsw
web modules will continue to work as expected.
Call backend code from the frontend