1

What's the best practice of including javascritps in salesforce? I want to minified and concat all js files used in our app. When we are developing we want to use js files as separte files but on production environment we want to have a single file.

2 Answers 2

2

You can write a query in your controller

public boolean runningInASandbox {get { return [SELECT Id, IsSandbox FROM Organization LIMIT 1].IsSandbox;} }

You can then use this boolean to select what static resource get to play

    <apex:outputPanel rendered="{!not(runningInASandbox)}" layout="none">
    //prod javascript reference
    </apex:outputPanel>
    <apex:outputPanel rendered="{!runningInASandbox}" layout="none">
    //sandbox javascript reference
    </apex:outputPanel>
1
  • I don't set up my dev environment in sandbox but I should set up in sandbox and that should work.
    – user3211
    Aug 11, 2015 at 3:54
2

Use a Static Resource.

A static resource can be an archive file (.zip etc) so you can bundle your separate Javascript files inside it.

Ant can help you Zip Stuff.

You could use requirejs to handle the loading of your Javascript modules so that your Javascript references will work irrespective of file structure. Cary Landholt's videos explain those concepts well.

You must log in to answer this question.

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