Can I use function in Site Code under Page Code?

I thought this was possible but when I create a function under Site Code Tab I can’t reach it from a call under the Page Code Tab.

Page Code below try calling verifyUser()


Site Code below where the export function verifyUser is located.

What do I do wrong?

2 Likes

Hi,
Firstly, I recommend reading the explanation here regarding the “page” and the “site” tabs of the code editor:


Moreover, I recommend creating a JS file in the public directory and import it. Code written in public files is shared by your site’s Backend, page code, and site code environments. Use public files to hold utility functions that can be called from multiple locations in your site’s code.

Best,
Tal.

So, you’re saying I should put my function (which is on my site code) in a .js file?

From the page that Tal linked,

Tip:
Code that you add to the Site tab runs on every page in your site. This can impact your site’s performance so it’s important to consider if you need the code to run on every page. If you have code that needs to run on some, but not all pages you may want to put it in a Public file and import it as needed.