Sencha Touch Cookbook
上QQ阅读APP看书,第一时间看更新

Setting up the production environment

This recipe describes the steps required to create a production-ready package of the application. These steps are mentioned for the Sencha Touch-related applications; however, they can also be applied to any JavaScript-based application.

Getting ready

Make sure that you have completed the steps outlined in the Setting up the browser-based development environment recipe.

How to do it...

Carry out the following steps:

  1. Trim down the Sencha Touch library by deleting the files and folders which are not required in the production environment. The following screenshot shows the files and folders which should be deleted from the sencha-touch folder:
    How to do it...
  2. Update the index.html file to include sencha-touch.js in place of sencha-touch-debug.js.
  3. Merge and minify your JavaScripts and CSS files. You may use the tool of your choice. Say you have created yapps-all.js (for now, it contains only the ch01_01.js) and yapps-all.css (this may contain the merged sencha-touch.css and any of our application-specific CSS file, say, yapps.css) as the merged and minified JavaScripts and CSS files, respectively.

    Note

    Sencha uses and recommends JSBuilder and YUI Compressor and you can read more about this at the following URL:http://www.sencha.com/products/jsbuilder.

  4. Remove the inclusion of the individual application-specific JavaScript files and CSS files from index.html.
  5. Include yapps-all.js and yapps-all.css.
  6. Deploy the application on your production server.

How it works...

In step 1, we removed the unwanted folders and files which are not required for a typical production deployment.

In step 2, we replaced the debug version of the library with the production ready version, which is a compressed and minified version of the debug version. This file will not have the comments and also the code is obfuscated.

In step 3, we merged all the JS/CSS files into one single file and minified them. You may want to find out the best way to combine the files. This is generally done to load the application quickly. You may choose to combine one or more files into one or create individual minified files. It is totally based on your project design and code structure.

In steps 4 and 5, we removed the individual inclusion of the JS and CSS files from index.html and included the merged and minified ones. This recipe does not show the PhoneGap-related JS file. However, if your application is using it, then make sure that you also minify it, as the default one is not the production ready file.

See also

  • The recipe named Setting up the browser-based development environment in this chapter
  • The recipe named Setting up the Android-based development environment in this chapter