Newer Version Available
JavaScript Remoting and Static HTML
Visualforce pages designed this way eschew many of the automatic, simplified features of standard Visualforce, in favor of taking more control over the request-response cycle, and performing page updates using JavaScript instead of page reloads. This can substantially improve the performance of the page, especially over the lower bandwidth, higher latency wireless network connections that make mobile devices so, well, mobile. The downside is that there is more code to write, and you need expertise in JavaScript, JavaScript remoting, HTML5, your mobile toolkit, and CSS, in addition to Apex and Visualforce. The upside of the downside is that you’re working with the latest, most advanced tools for mobile development, and the pages you can build are the best, most complete way to “snap in” custom functionality that fully integrates with the app.
You can build desktop Visualforce pages using this approach as well as pages for the Salesforce app. It’s even possible to share such pages between the two environments by customizing the styling, though it’s a challenge to closely match the full Salesforce site look and feel. Most importantly, the pages you design can be fully responsive, adapting and working across a range of devices and form factors.
Applying this Approach to Your Visualforce Pages
To use this approach for creating pages for the Salesforce app, follow this general process:
- Install your preferred Salesforce Mobile Pack (available on Salesforce) into your organization as a static resource.
- Set your page’s docType to html-5.0.
Strongly consider disabling the standard stylesheets and header. For example:
- Add scripts and styles from your chosen mobile toolkit to the page using
Visualforce resource tags. For
example:
- Use HTML5 and your mobile toolkit’s tags and attributes to create a page skeleton.
- Add JavaScript functions to the page as handlers to respond to user interaction. Use JavaScript remoting to call Apex @RemoteAction methods that retrieve records, perform DML, and so on.
- Add additional JavaScript functions to handle user actions and page updates. Perform page updates by constructing HTML elements in JavaScript, and then adding or appending them to the page skeleton.
Example of a JavaScript Remoting and Static HTML Page
Although this page can be used in the full Salesforce site, it’s designed as a Salesforce app page and looks very different than a normal Visualforce page.