In my page, the javascript coding is as follows

    function validationcomplete(){
        var strg1=document.getElementById("Endereço").value;
        var strg2=document.getElementById("Numero").value;      
        var strg1=document.getElementById("Endereço").value;
        var strg2=document.getElementById("Numero").value;
        document.getElementById("Endereço").value=strg2+" "+strg1; 

        alert("Potvrđujemo da je vaš dopis uspješno prosljeđen Službi odnosa sa strankam Dacia");

I have to replace this coding with a static JS resource file. How can I do this?

  • Note that its the JavaScript that should go in the static resource so don't include the HTML script tag; that remains in your Visualforce page.
    – Keith C
    Jun 16, 2015 at 7:48

3 Answers 3


just store this file in static resource , and after that include this in your vf page using below syntax!!!

<apex:includeScript value="{!$Resource.javascriptname}"/>

I prefer not to use <apex:includeScript> for performance reasons.

From the Visualforce Performance Best Practices guide:

Consider including JavaScript files using a standard HTML tag right before your closing tag instead

So I usually do :

<script src="{!$Resource.myscript}"></script>

What you have to do is first save the code as a separate JS file then create a new static resource in your Salesforce Org and add the JS File into the resource.Now to include the javascript code in your vf page just add this line(say your static resource is named as test)

apex:includeScript value="{! $Resource.test}"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .