function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arun_PaliArun_Pali 

Best practise for using shared functions ..

Folks,
I am looking out for a way to share a bunch of common java script functions between 2 visual force pages. Is there a way to achieve this.

Page1.page
<apex:page>
<script type="text/javascript">
     function a() {
     }

     function b() {
     }
</script>
// some more stuff specific to Page 1
</apex:page>

Page2.page

<apex:page>
<script type="text/javascript">
     function a() {
     }

     function b() {
     }
</script>
// some more stuff specific to Page 2
</apex:page>

Basically, I wanted to put these JS functions in a single JS file and then access it from both the pages. Is there a way to do this? If so, how & where can we store this JS file ? Pls advise.


Thanks.
iceberg4uiceberg4u
Upload your js file in the static resource and you can access the js functions from there.
Heres how you use it in vf page:-

<script type="text/javascript" src="{!URLFOR($Resource.scripts,'scripts/common.js')}"></script>
Arun_PaliArun_Pali
Thanks iceberg4u. I will try this out ..