How to get the path of js file in static resource.

for ex: /resource/1301987741012/resourceName/JSFileName.Js

what is this no. 1301987741012 .is it an Id of resource ?

  • My answer assumes you are trying to get this information from a Visualforce page. Is this what you need it for, or something else?
    – dphil
    Apr 10, 2014 at 20:58
  • It helps give you a correct answer if you explain what you need the information for.
    – dphil
    Apr 10, 2014 at 21:00
  • I am assigning the path of js file to a variable in js file
    – sfdc
    Apr 10, 2014 at 21:06
  • If the logic originates from a Visualforce page, best to pass this value into your JavaScript from the Visualforce.
    – Keith C
    Apr 10, 2014 at 21:12

4 Answers 4


In Visualforce, use

!URLFOR($Resource.myResource, 'js/JSFileName.js')

or whatever the resource name and path to the file you want is.



This Delivering Static Resources with Visualforce article provides the background. The number is a timestamp.

Based on that you can write Apex code like this:

Map<String, String> m = new Map<String, String>();
for (StaticResource r : [
        select NamespacePrefix, Name, LastModifiedDate
        from StaticResource
        where Name in :names
        and CacheControl = 'Public'
        ]) {
    m.put(r.Name, 'resource/' + r.LastModifiedDate.getTime() + '/'
            + (r.NamespacePrefix != null ? r.NamespacePrefix + '__' : '') + r.Name);
 return m;

to obtain the URLs (or just the number if that is what you want).

But the cleanest approach is obviously to use the built-in Visualforce mechanisms described in Referencing a Static Resource in Visualforce Markup to generate the URL including the timestamp for you.

  • 1
    Additionally, if you don't wish to use the 'cache busting' timestamp in the resource path it can be omitted. Doing so introduces the possibility that you may see an old resource retrieved from your browser's cache.
    – Mark Pond
    Apr 10, 2014 at 22:09

Your problem is that of "referencing a static resource from another static resource". In this link , under the Static Resource Bundles section, you find useful info.

The number you mention is the static resource ID that salesforce provides for the static resource you upload. This ID changes for each run. You can see them under Sources tab in Chrome's developer console. (Refer these screen shots).
Run1: Static Resource id is 17067916541000

Run1: Static Resource id is 13019877741012

A workaround I figured is to add this line in my VFpage (MyStaticResource is the name of the Static Resource bundle that I've uploaded)

var resourceId='{!URLFOR($Resource.MyStaticResource)}';

Now I can access this var inside my javascripts (those that are bundled with the static resource itself).

For example: My Static resource looks like this:
   |       |--Jasmine.jpg
   |       |--Rose.jpg
   |       |--image_load.js

My Visualforce code is (
<apex:page >     <table>        <tr>          <td id="flower_page"></td>        <\tr>     <\table> </apex:page>

My Javascript code is ... $("#flower_page").html( "<div class=\"img-flower\"><img src=\""+resourceId+"/"+ Rose.jpg + "\" width=\"50\" height=\"50\" /></div>" ); ...

This would emit the following code. ... <table> <tr> <td id="flower_page"> <div class="img-flower"> <img src="/resource/1412387865123/MyStaticResource/img/Rose.jpg" width="50" height="50" /> </div> </td> ...

I hope this answers your question.

Let me know if you need more help on this.



I think it is some sort of identifier for the resource. The following link will explain how to include javascript from a static resource:


  • how to get the identifier for the resource
    – sfdc
    Apr 10, 2014 at 20:55
  • What do you need it for?
    – dphil
    Apr 10, 2014 at 20:55

You must log in to answer this question.

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