5

So at the moment when I want to make a quick tweak in a javascript file that enhances a Visualforce page, I have to go:

  1. Setup >> Development >> Static Resources
  2. Find my script in the list (takes a few clicks and page refreshes if it is low down on the list)
  3. Click Delete I get a list of places where the resource is used
  4. Open the pages mentioned in the code editor
  5. Comment out the places where the script is used
  6. Find the resource in the list again and try delete (almost there, don't give up now)
  7. Now add that missing angle bracket in my desktop editor
  8. Upload the file giving it the same name as before
  9. Hop over in to the online code editor and remove the comments around all the places where the script is included and save.

Anyone know of a shorter routine?

4 Answers 4

12

You can just reupload the zip file again, no need to delete & reinsert. Simply click "Edit" and use the file upload field :)

And during development I tend to work on raw JS files (not zipped), I can then edit code directly in Eclipse IDE for example. I package up zips only when I'm ready to promote it to testing / production. You could reference both the "basic" static resource and later temporary static res with just this one troublesome JS file, if it contains function definitions they'll be overwritten.

1
  • Oh my, how did I miss that? I guess I expected a full code editor when I first clicked on Edit and then it looked like I could only edit the resource name. Thanks for saving me hours!
    – JannieT
    Commented Dec 13, 2012 at 4:48
8

I don't know if this would be a frowned upon approach or not, but in my frustration with what you have described above (whilst in development only) I created a Component to allow dynamic editing of Javascript

<apex:component controller="MappingController">
  <script type="text/javascript">
    var greeting = "hello";
  </script>
</apex:component>

Think I had the controller in there because I was doing some remoting.

EDIT: Added VF Page source

<apex:page standardController="Project__c" extensions="MappingController" standardStylesheets="false">
  <c:Styles /> <!-- dynamic stylesheet editing here -->
  <apex:stylesheet value="{!URLFOR($Resource.jquery3, 'css/custom-theme/jquery-ui-1.8.23.custom.css')}"/>
  <apex:includeScript value="{!URLFOR($Resource.jquery3, 'js/jquery-1.8.0.min.js')}"/>
  <apex:includeScript value="{!URLFOR($Resource.jquery3, 'js/jquery-ui-1.8.23.custom.min.js')}"/>
  <apex:sectionHeader title="Edit" subtitle="Mapping" />
    <apex:form >
      <div>some html or other</div>
    </apex:form>
    <c:MappingCanvas />        <!-- dynamic javascript editing here -->
    <c:Scripts />        
</apex:page>
5
  • Hey Phil great idea. So you store all javascript stuff in just one component and load it just after apex:page notation? Commented Dec 12, 2012 at 12:06
  • @mast0r - basically yes, though looking at my source I have it at the bottom (not sure if there is a reason for that) - i'll edit my answer to show you. Commented Dec 12, 2012 at 12:10
  • 2
    Putting JavaScript at the bottom is a common optimization technique; it sometimes will allow browsers to render pages quicker.
    – Mike Chale
    Commented Dec 12, 2012 at 12:22
  • @MikeChale, it may be a common optimization technique, but that isn't why I put it there, I think it was probably more to do with making my source easily visible from the clutter at the top when debugging. Thanks for the tip though. Commented Dec 12, 2012 at 12:25
  • Good tip, Phil!
    – JannieT
    Commented Dec 13, 2012 at 4:48
2

FWIW - It's also possible to update Static Resources via the Migration Tool. In theory you could have your JavaScript as part of source control and loaded automatically into your org as part of a CI loop.

1

Why so complicated? I'v created a static resource and uploaded all my JavaScripts as one zip-file (without .zip ending). Every tyme i want to update my script i just swapping out thet zip-file. Thats all.

You must log in to answer this question.

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