Script processing

When the BlackBerry® Browser parses a web page, it processes JavaScript® as it is encountered. Scripts can be inline or external.

When the browser encounters a <script> element, it pauses web page rendering activities while it retrieves and then executes the script. You can use the defer attribute to prevent the script from being processed until it is called. Unless the initial web page content relies on the outcome of a script, you should use the defer attribute.

In BlackBerry® Device Software version 4.5 or earlier, if the BlackBerry Browser encounters any script that produces common dynamic HTML effects, the browser executes without error but produces no visual effect. JavaScript that is not supported simply produces an error, which, unless handled within the script, prevents the script from executing any further.

Script processing behavior varies slightly, depending on the network gateway the browser uses to access the content.

  • If the content is accessed through the BlackBerry MDS Connection Service network gateway or the BlackBerry Internet Service Browsing network gateway, the network gateway typically pre-compiles the JavaScript before sending it to the BlackBerry device. The server can compile the script faster than the device can. When the server compiles the script, it can reduce the time required for the browser to process the script, thereby reducing the length of time that the browser is blocked from rendering the web page.

    One obstacle to server-side preprocessing of the JavaScript occurs when an eval() function is used to execute JavaScript code. The network gateway cannot precompile the contents of an eval() function. Instead, the BlackBerry Browser must compile the code.

  • If the content is accessed through a WAP network gateway, the browser compiles the code and reads any auxiliary JavaScript support libraries that are referenced from the web page.

The BlackBerry Browser supports a number of compression algorithms. In general, compressing content targeting the BlackBerry Browser offers little benefit in terms of reducing data transfer speeds or network traffic; if the content is accessed through the BlackBerry MDS Connection Service network gateway or the BlackBerry Internet Service Browsing network gateway, the network gateway unpacks the script before it compiles and recompresses the script for efficient transfer over the wireless network. If you use compression algorithms that contain the eval() function, the algorithms can hinder performance; the network gateway will unpack and recompress the script for transfer, but since the network gateway cannot precompile the enclosed code, the benefit derived from precompiling on the server side is reduced.

Index


Was this information helpful? Send us your comments.