7

In my web app, you can open an iframe which load a report (similar to an excel spreadsheet). The reports open fine for a while (15-20 times). At some point, I will start always getting JS errors about kendo being undefined and I occasionally get "Insufficient memory" errors in IE console.

As you can see in my HTML , the kendo.all.min.js file comes before the kendo.sage.custom.min.js file.

<script type="text/javascript" src="/Scripts/kendo/web/kendo.all.min.js"></script>
<script type="text/javascript" src="/Scripts/kendo/kendo.sage.custom.min.js"></script>

When all goes well, fiddler showsenter image description here

But when i start getting errors, I can see the following : scripts wrong order

So for some reason, after using my app for a while, the scripts will load in the wrong order.

So I added console.log("all") and console.log("sage")at the top of each script. When working normally, I can see in order "all" and then "sage", but when I start getting the kendo undefined error, all i see is the "sage" log, never the "all".

We are using ASP.NET MVC and the scripts are in our layout file in the head section.

What could cause the scripts to be run in the wrong order ?

Simon ML
  • 1,819
  • 2
  • 14
  • 32
  • Well how is the order changing? How are you adding the scripts to the page? – epascarello Nov 26 '15 at 21:31
  • That is what I'm looking for, I do nothing differently to get this result. Like I said, only by repeatedly opening the same report, at one point the scripts aren't loaded in the right order anymore. The scripts are all in the , in the right order. – Simon ML Nov 26 '15 at 21:34
  • Is your cache on or off? Because cached scripts would load faster and depending on your cache limit, maybe only some would be, hence your result? – Zze Nov 26 '15 at 21:43
  • @Zze This time cache was off, but I had it happen with or without cache – Simon ML Nov 26 '15 at 21:45
  • Hmmmmm, maybe you could ajax them in linearly on load? – Zze Nov 26 '15 at 22:17
  • You mean load them with AJAX one after the other ? Like when the first is loaded, make another AJAX call to load the second ? – Simon ML Nov 26 '15 at 22:23

1 Answers1

1

Are all the script in the head section? If not then move the custom to the footer and load the custom script after the page has loaded, this will ensure that the custom file loads after the main file

$(window).load(function(){
var element = document.createElement("script");
element.src = "/Scripts/kendo/kendo.sage.custom.min.js";
document.body.appendChild(element);
});

And for your answer, refer to this link load and execute order of scripts

Community
  • 1
  • 1
Lucky Chingi
  • 2,248
  • 1
  • 10
  • 15
  • Yes my scripts are all in the head section and I would rather not play to much with the orders of the files since there are dependencies between them. The Kendo file is the second one (juste after jquery) and should be loaded before all others. – Simon ML Nov 26 '15 at 21:25
  • I understand, but It would help if you figure out the dependencies and move some to footer. or load them once the window has loaded – Lucky Chingi Nov 26 '15 at 21:30
  • I think I will try to bundle all my JS together to make only one file be downloaded. Do you think that could be similar to your solution ? – Simon ML Nov 26 '15 at 21:51
  • 1
    if you plan to bundle also remember to compress / minify. In fact you should minify all js – Lucky Chingi Nov 26 '15 at 21:58