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
udhayakumar thangarajuudhayakumar thangaraju 

Standalone static resource is not working in Visualforce Page

I created a static resource called jsquery by uploading Jquery.js and then tried to include the static resource in VF as follows

<apex:page >   
<!--<apex:includeScript value="{!URLFOR($Resource.jsquery, 'jquery-1.11.2.min.js')}"/>-->
    <apex:includeScript value="{$Resource.jsquery}"/>
    <script>   
    alert('Test...');
    jQuery(document).ready(function() {           
            alert("Hello My Jquery is working!!!!"); 
    });       
    </script>
    <a href="#">Test</a>
</apex:page>

However, while executing the visualforce page, first alert is shown and second is not shown. Browser console says JQuery is not an object or null.

Can some help me to find out what is going wrong?
Best Answer chosen by udhayakumar thangaraju
Vla ChaVla Cha
Hi Udhayakumar, 

you need to use <apex:includeScript value="{!$Resource.jsquery}"/> instead of <apex:includeScript value="{$Resource.jsquery}"/>

Cheers!

All Answers

Vla ChaVla Cha
Hi Udhayakumar, 

you need to use <apex:includeScript value="{!$Resource.jsquery}"/> instead of <apex:includeScript value="{$Resource.jsquery}"/>

Cheers!
This was selected as the best answer
sfdcdevsfdcdev
To reference a stand-alone file, use $Resource.<resource_name> as a merge field, where<resource_name> is the name you specified when you uploaded the resource. For example:
 
<apex:includeScript value="{!$Resource.MyJavascriptFile}"/>

In your case, if you have uploaded a stand-alone file "'jquery-1.11.2.min.js" and named it "jsquery", then refer it like this:
 
<apex:includeScript value="{!$Resource.jsquery}"/>

In above code, you've missed "!" in merge field.         

For more info, visit the following link:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_resources.htm