OperaMini and Javascript
Recently, there was a conversation about OperaMini's capabilities for working with JavaScript, in particular AJAX. The topic is interesting, I think that some of my observations may be useful to someone.
We will consider the fourth version of OperaMini as the most current at the moment.
Additionally, the article used some information from the Opera developers site .
So, OperaMini, the browser version for phones in which the quality of the built-in walker is unsatisfactory. The main feature is that it is not a direct downloads and parses the page and uses for this intermediate server itself Opera, where the requested page is optimized in a more uzhaty format OBML(Opera Binary Markup Language) claims that winnings can reach 90%!
Since OperaMini can work on a huge number of MIDP 2 and even MIDP 1 wireless devices, the limitations on computing resources are very large and there is no point in directly implementing a JavaScript engine on the device, and just like with respect to HTML / CSS OperaMini acts only in As a terminal, then a similar but more complex approach is used for JavaScript.
In principle, it is logical that OperaMini uses a JavaScript engine similar to the one built into the main Opera. However, the main difference is that everything is possible on the server, of course, with some limitations.
Everything that should be done before the page is completed (for example, onLoad scripts) is executed on the server before the page is issued, this also implies a logical restriction on the execution time of sequentially called functions (for example, setInterval () , setTimeout ()and delay () simply prohibited to execute). And of course, as soon as the page is sent to the client, all scripts stop.
Example 1 :
Returns a page with the text
Hello Habr
AFTER
What opportunities remain on the client side?
Scripts are executed that are associated with form events, such as:
OnClick events are also available for all other page elements, not just forms.
Well, the usual alert ('HI') works without any reboot.
Example 2:
Pressing the button will reload the page and replace BEFORE with CLICKED.
Example 3 :
When you change the selected item, the page will reload and alert () will be displayed.
Other events like onMouseOver / -Out / -Down / -Up, onKeyDown / -KeyPress and onBlur, onFocus will be ignored.
Now about AJAX
In view of the above limitations, it is clear that AJAX cannot work as usual. But there is good news, XMLHttpRequest is supported! Therefore, many sites actively using AJAX will work, albeit with some limitations.
The main thing that had to be sacrificed was the function of constantly polling the server for new data, for example, real-time chat cannot be done, and in GMail notifications of new letters will not appear by themselves.
Those scripts that are executed as a response to user actions, clicking with the mouse, changing input fields will work, albeit with a page reload, which significantly reduces the importance of using AJAX, but at least it works as intended.
We will consider the fourth version of OperaMini as the most current at the moment.
Additionally, the article used some information from the Opera developers site .
So, OperaMini, the browser version for phones in which the quality of the built-in walker is unsatisfactory. The main feature is that it is not a direct downloads and parses the page and uses for this intermediate server itself Opera, where the requested page is optimized in a more uzhaty format OBML(Opera Binary Markup Language) claims that winnings can reach 90%!
Since OperaMini can work on a huge number of MIDP 2 and even MIDP 1 wireless devices, the limitations on computing resources are very large and there is no point in directly implementing a JavaScript engine on the device, and just like with respect to HTML / CSS OperaMini acts only in As a terminal, then a similar but more complex approach is used for JavaScript.
In principle, it is logical that OperaMini uses a JavaScript engine similar to the one built into the main Opera. However, the main difference is that everything is possible on the server, of course, with some limitations.
- Limited support for DOM related events.
- Inability to execute background scripts.
- Very limited use of AJAX.
Everything that should be done before the page is completed (for example, onLoad scripts) is executed on the server before the page is issued, this also implies a logical restriction on the execution time of sequentially called functions (for example, setInterval () , setTimeout ()
Example 1 :
Returns a page with the text
Hello Habr
AFTER
OperaMini 4.2
Hello Habr
AFTER
* This source code was highlighted with Source Code Highlighter.
What opportunities remain on the client side?
Scripts are executed that are associated with form events, such as:
- onSubmit - if the form has a handler for this event, when sending data, it unconditionally uploads to the server on which the script processes and the result is sent back to the client.
- onChange - works similarly, when you select an item from the list that has a handler for this event, the entire page is completely reloaded, and the desired function is executed on the server.
- onClick - for form buttons - also works on the server and reloads the page with the result.
OnClick events are also available for all other page elements, not just forms.
Well, the usual alert ('HI') works without any reboot.
Example 2:
Pressing the button will reload the page and replace BEFORE with CLICKED.
OperaMini 4.2
Hello Habr
BEFORE
type='button'
value='Action test' onclick='document.getElementById("onLoadChangeMe").innerHTML="CLICKED"'
/>
* This source code was highlighted with Source Code Highlighter.
Example 3 :
When you change the selected item, the page will reload and alert () will be displayed.
* This source code was highlighted with Source Code Highlighter.
Other events like onMouseOver / -Out / -Down / -Up, onKeyDown / -KeyPress and onBlur, onFocus will be ignored.
Now about AJAX
In view of the above limitations, it is clear that AJAX cannot work as usual. But there is good news, XMLHttpRequest is supported! Therefore, many sites actively using AJAX will work, albeit with some limitations.
The main thing that had to be sacrificed was the function of constantly polling the server for new data, for example, real-time chat cannot be done, and in GMail notifications of new letters will not appear by themselves.
Those scripts that are executed as a response to user actions, clicking with the mouse, changing input fields will work, albeit with a page reload, which significantly reduces the importance of using AJAX, but at least it works as intended.