I am developing a Salesforce application that is using jQuery, jQueryUI and a custom plugin. The script tags in the page markup are in the correct order:

<script type="text/javascript" 
<script type="text/javascript" 
<script type="text/javascript" 

All three are loading (can view the code in Chrome Development Tools), but when inspecting the Network tab they are loading in a different order; the plug-in is loading before the jQueryUi. This means the plugin is failing (there is no widget method).

Why is this happening and how can I correct it?



The goal is to add the scripts to an existing form (i.e. Account Edit) to add functionality.

Currently I have a Visualforce page that is the javascript to dynamically load the js files from static resources, the file paths are using '{!URLFOR($Resource.name)}'.

They are being added, just not in the same order. I've found that dynamically added js files ARE added async. So now I'm struggling how to over come this.

  • IMO You can not control order of loading of 3 scripts in browser(even if backend is not salesforce). Nov 11, 2013 at 12:55

3 Answers 3


I don't think this is a visual force problem, resources from a browser are loaded asynchronously, if you have dependencies, try using getScript



  • Alternatively, require.js, which is also small, and cross-browser compatible.
    – sfdcfox
    Jan 20, 2014 at 21:29


Could you try using 'apex:includescript' instead of using HTML tag and see how its loading in the network tab?

<apex:includeScript value="{!URLFOR($Resource.afdpce, 'afdpce__JQuery/js/jquery-1.10.2.min.js')}" />

Here i assumed "afdpce" is the Static Resource name of the resource and it is zipped

  • adfpce is the namespace, jQuery is the static resource. I've expanded the question (above), I may be approaching the problem the wrong way.
    – KevinManx
    Nov 11, 2013 at 16:03
  • When you checked your Network Resource in Chrome console, is any one your resource "cached"? I mean cached version would result in faster loading than others. Is the caching set to "PUBLIC" for your resource in Salesforce ?
    – Jag
    Nov 11, 2013 at 16:35

@Kevin, can you defer the execution of any JS code in your plugin to after page load? @Ganesh is right - you can't control the timing of the load process. Wrote lots of JS/jQuery code - never a problem starting things after page load.

You must log in to answer this question.

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