Share javascript code

I have written a javascript function at a web page and would like to make it re-usable at other web pages, how to achieve it ?

Check this out and consider creating a public web module.

I’m using the public scope today to define a set of “constants” in a script called globalVars.js like this:

export let forumVars = {
    posts_db : 'Forum/Posts',
    comments_db: 'Forum/Comments',
    categories_db : 'Forum/Categories'
}

Now, from my backend or frontend scripts, I can access these values like this:

import { forumVars } from 'public/globalVars.js';
return wixData.query(forumVars.posts_db)
...

Naturally, you can also create functions in a script file like this in the public scope.

Refer to this thread for additional conversation.

I hope this helps :smile:

It 's great. Thx