Javascript function size limit on Opera?
-
Is there some limitation of javascript function length on Opera? I've tested, how efficient solution will be to provide dictionaries as javascript function that tests what key we give and return proper values. The advantage of that solution would be, that dictionaries would be cached without LocalStorage from HTML5, using browser cache mechanism only. I've done test with address database, writing function, which fragment is here: window.dict = {}; dict.getStreets = function (sym) { if (sym == '46') { return [["Andrzeja","10028"],["B\u0142o\u0144ska","34182"],["Cisowa","10027"],["Dojazdowa","177799"],["Dolna","126726"],["Dzia\u0142kowa","153180"],["Dzikiej R\u00f3\u017cy","211051"],["Fio\u0142kowa","98636"],["Gimnazjalna","126727"],["Gwia\u017adzista","126728"],["Jana","34189"],["Jod\u0142owa","34183"],["Majowa","34184"],["Mi\u0142a","98637"],["Orzechowa","34185"],["Osiedlowa","153181"],["Polowa","34186"],["Po\u0142udniowa","98638"],["Prosta","211052"],["Purzyckiego","126729"],["R\u00f3\u017cana","211053"],["S\u0142owicza","224648"],["Spokojna","34187"],["Stra\u017cacka","98639"],["Szarotki","34188"],["\u015awierkowa","224596"],["Weso\u0142a","153182"],["Wschodnia","126730"],["Zachodnia","34190"]]; } else if (sym == '98') { return [["Bia\u0142ych Brz\u00f3z","177802"],["Calineczki","34192"],["Chabrowa","98640"],["Czarodziejska","98641"],["D\u0142uga","10029"],["Dworcowa","34191"],["Familijna","68666"],["Kasztanowa","153183"],["Konwaliowa","217850"],["Ko\u015bcielna","10030"],["Kr\u0119ta","34193"],["Le\u015bna","177803"],["Lipowa","153184"],["\u0141\u00f3dzka","217851"],["Malownicza","177804"],["Masztowa","217852"],["Milenijna","10031"],["P\u00f3\u0142nocna","10032"],["Przesmyk","10033"],["Romantyczna","34720"],["Skrajna","98642"],["Sosnowa","98643"],["Stokrotki","126731"],["T\u0119czowa","10034"],["Uko\u015bna","68667"],["Urocza","34721"],["Ustronna","98644"],["Zaciszna","34722"],["Zau\u0142ek","217853"]]; } else if (sym == '224') { return [["Maj\u0105tkowa","217854"],["Orionist\u00f3w","153185"],["Wiosenna","98645"]]; } else if (sym == '394') { return [["Kwiatowa","177805"],["Sochaczewska","217855"]]; } else if (sym == '460') { return [["Grodziska","34723"],["\u0141\u0105ki","98647"],["Nowakowskiego","217856"],["\u017buk\u00f3wka","95137"]]; // ...... about 5MB of data goes here } else return null; }; The whole JavaScipt has over 5MB length. This works under FireFox (very slow, as I've supposed), IE 9 and Chrome (quite fast), but under Opera it is not working. When I've limited function's size, it works, but with full size there's not even function getStreets set on dict object. So I see for sure that Opera does not allow to create such big functions, as only from 'big' browsers. My question is, if it is somewhere documented what the limits are, or it is just some buffer overflow (or anything similar) in Opera's javascript engine? update The case with dictionaries was only an inspiration that made this code to be generated. The question is about limits to the Opera javascript parser, not the other way the code above could be written
-
Answer:
This is a known limitation which will soon be history: it's got nothing to do with the size of the function, but there is a limit to the number of chained if..else if.. statements you can have. In this test and on my computer the limit is 1020 chained statements: http://jsfiddle.net/8RAn8/ but I'm not sure if this is really a static hard-coded limit or depending on some parameters. If you remove the else from the ..else if.. chaining it runs just fine: http://jsfiddle.net/8RAn8/1/ and I've tested more than 15000 if blocks successfully without else. We're about to fix this bug and change the limit to something closer to what other browsers have.
lechlukasz at Stack Overflow Visit the source
Other answers
Yes, there are some limitations. No, I don't know what they are exactly. Sorry that this is a fairly useless answer..
hallvors
Related Q & A:
- How to create dynamic function in javascript?Best solution by Stack Overflow
- How to access a nested function from another nested function in javascript?Best solution by devarticles.com
- How to call Javascript function in PHP?Best solution by Stack Overflow
- What is the size limit on Yahoo mail?Best solution by Yahoo! Answers
- What is the legal size limit on trout in california?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.