Example: Serving the Appropriate Javascript Libraries
To provide the correct version of Javascript libraries, create a separate bundle for each Salesforce Mobile SDK version you use. Then, provide Apex code on the server that downloads the required version.
-
For each Salesforce Mobile SDK version that your application supports, do the following.
-
Create a ZIP file containing the Javascript libraries from the intended SDK version.
-
Upload the ZIP file to your org as a static resource.
For example, if you ship a client that uses Salesforce Mobile SDK v. 1.3, add these files to your ZIP file:
cordova.force.js
SalesforceOAuthPlugin.js
bootconfig.js
cordova-1.8.1.js
, which you should rename ascordova.js
In your bundle, it’s permissible to rename the Cordova Javascript library as
cordova.js
(orPhoneGap.js
if you’re packaging a version that uses aPhoneGap-*x.x*.js
library.) -
-
Create an Apex controller that determines which bundle to use. In your controller code, parse the user agent string to find which version the client is using.
-
In your org, from Setup, click Develop | Apex Class.
-
Create a new Apex controller named
SDKLibController
with the following definition.
-
-
Create a Visualforce page for each library in the bundle, and use that page to redirect the client to that library.
For example, for the SalesforceOAuthPlugin library:
-
In your org, from Setup, enter
Visualforce Pages
in the Quick Find box, then select Visualforce Pages. -
Create a new page called “SalesforceOAuthPlugin” with the following definition.
-
Reference the VisualForce page in a
<script>
tag in your HTML code. Be sure to point to the page you created in step 3b. For example:Provide a separate
<script>
tag for each library in your bundle.
-