4

I am trying to build a Lightning Component, and have referenced external JS library functions via Static Resource. But since I'm in development currently, the JS functions file is being modified heavily, but the Preview Mode of Lightning Component App, is not refreshing the updated JS file.

The static resource is a Zip file, and with every function change I reupload the static resource and call the updated function in Javascript Controller. But it does not reflect the changes in the preview. How can I sort this out, this is troubling and consuming most of my time.

  • Are you using any tool or IDE ?Use IDE like Atom or Mavensmate on Sublime to mke your life simpler where you can edit static resources provided you dont zip until final production push . – Mohith Shrivastava Sep 23 '15 at 15:58
2

Usually the static resource files are cached in the browser. So in case you make minor change in the files they are not reflected immediately.

So to always get the latest changes in the browser, you can either do Ctrl+F5 or update VF page with the verison number in the resource.

Before Change:

<script type="text/javascript" src="{!URLFOR($Resource.myStaticResource, 'myApp/js/sequenceOrder.js')}"></script>

after Change:

<script type="text/javascript" src="{!URLFOR($Resource.myStaticResource, 'myApp/js/sequenceOrder.js?ver=001')}"></script>

Just increment the version in the parameter and that will fetch the changes in the view. I haven't worked with Lightning components, but this what works out for me in VF.

  • 1
    Great it worked for similar caching problem. – Pranay Jaiswal Jun 19 '16 at 7:19
0

The way we set our dev tools are important here to avoid frustration .

Use IDE like Atom or Mavensmate on Sublime to mke your life simpler where you can edit static resources provided you dont zip until final production push .

You can also use some sophisticated build system like Gulp or Grunt to manage your dependencies and JS files currently unzipped .

Unless your files are PROD ready dont zip them and reference individually for now .

  • That also i ve given a try. But not the ide. I did tried uploading js function file and referenced in lntg:requirejs tag but same issue, it still loading previous cached js file instead of static resource js file whichbis not a zipped resource but direct resource. :-( – VarunC Sep 23 '15 at 16:11
  • switch different browsers and check the behavior .I wont be surprised if this is a bug – Mohith Shrivastava Sep 23 '15 at 16:22
  • it didn't work with different browsers as well, same result. – VarunC Sep 23 '15 at 17:38
0

Varun, i suggest you to use some automatic build mechanism for static resources. Please find the video link. https://www.youtube.com/watch?v=W4Fyiz4Gocw

For quick solution, you might want to keep switching your zip file version, each time you upload the zip file. Like zip1.zip rename it to zip2.zip before upload, then next upload rename it to zip1.zip and keep switching each time you upload, you would also need to correctly reference it, in your Visualforce/Lightning code, it'll do the trick for you.

However you could directly upload the js file without zipping and edit it even in developer console.

Hope it helps. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.