Recently, there was a conversation about the possibilities OperaMini to work 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 uses some information from
the Opera developers site .
')
So, OperaMini, the browser version for phones in which the quality of the built-in browser is unsatisfactory. The main feature is that it does not directly download and parse the pages, but instead uses intermediate servers of Opera itself, on which the requested page is optimized into some more compressed OBML format (Opera Binary Markup Language), it is stated that the winnings can reach 90%!
So, as OperaMini can work on a huge number of MIDP 2 and even MIDP 1 wireless devices, the limitations on computing resources are quite large and there is no sense in directly implementing the JavaScript engine on the device, and just as with respect to HTML / CSS, OperaMini only appears in As a terminal, 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 performed on the server whenever possible, of course with some limitations.
- Limited support for DOM related events.
- Inability to execute background scripts.
- Very limited options for using AJAX.
Everything that should be executed before the completion of the page formation (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 successively called functions (for example,
setInterval () ,
setTimeout () and delay () simply forbidden to perform). And of course, as soon as the page is sent to the client, all the scripts stop.
Example 1 :
Will display a text page
Hello Habr
AFTER
< html >
< head >
< title > OperaMini 4.2 </ title >
</ head >
< body onload ='document.getElementById("onLoadChangeMe").innerHTML="AFTER"' >
Hello Habr
< div id ='onLoadChangeMe' > BEFORE </ div >
</ body >
</ html >
* This source code was highlighted with Source Code Highlighter .
What opportunities remain on the client side?
Run scripts associated with form events, such as:
- onSubmit - if the form has a handler for this event, when sending data, they are unconditionally loaded onto the server, on which the script runs and the result is sent back to the client.
- onChange - works in the same way, when you select an item from the list that has a handler for this event, the entire page is completely reloaded, and the necessary function is executed on the server.
- onClick - for form buttons - will also work on the server and reload 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.
< html >
< head >
< title > OperaMini 4.2 </ title >
</ head >
< body onload ='document.getElementById("onLoadChangeMe").innerHTML="AFTER"' >
Hello Habr
< div id ='onLoadChangeMe' > BEFORE </ div >
< input
type ='button'
value ='Action test' onclick ='document.getElementById("onLoadChangeMe").innerHTML="CLICKED"'
/>
</ body >
</ html >
* 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 shown.
< hr />
< select id ='tstSel' onchange ='alert(this.selectedIndex)' >
< option value ='Uno' > Uno </ option >
< option value ='Duo' > Duo </ option >
< option value ='Tres' > Tres </ option >
</ select >
* This source code was highlighted with Source Code Highlighter .
Other events such as
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 restrictions.
The main thing that had to be sacrificed was the functions of constantly polling the server for new data, for example, real-time chat would not work, and notifications about new letters will not appear in GMail by themselves.
Those scripts that are executed as a response to user actions, clicking with the mouse, changes to the input fields will work, albeit with a page reload, which significantly reduces the importance of using AJAX, but at least it works as intended.