Skip to content

Commit 5116b8b

Browse files
author
jossonsmith
committed
Opera will also take another try to load failed *.js.
IE will take less time (0.5s << 15s) checking unexisted local *.js resources.
1 parent e9a94a7 commit 5116b8b

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

sources/net.sf.j2s.java.core/src/java/lang/ClassLoader.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,27 @@ ClazzLoader.loadScript = function (file) {
695695
* What about Safari?
696696
*/
697697
/*
698-
* Opera will trigger onload event even there are no related *.js
698+
* Opera will trigger onload event even there are no *.js existed
699699
*/
700700
script.onload = function () {
701-
this.onload = null;
701+
this.onload = null;
702702
var path = arguments.callee.path;
703-
ClazzLoader.scriptLoaded (path);
703+
if (!ClazzLoader.isInnerLoaded
704+
&& navigator.userAgent.indexOf("Opera") >= 0) {
705+
// Opera will not take another try.
706+
var fss = ClazzLoader.failedScripts;
707+
if (fss[path] == null) {
708+
// silently take another try for bad network
709+
fss[path] = 1;
710+
ClazzLoader.loadedScripts[path] = false;
711+
ClazzLoader.loadScript (path);
712+
return;
713+
} else {
714+
alert ("[Java2Script] Error in loading " + path + "!");
715+
}
716+
} else {
717+
ClazzLoader.scriptLoaded (path);
718+
}
704719
if (ClazzLoader.loadingTimeLag >= 0) {
705720
window.setTimeout (function () {
706721
ClazzLoader.tryToLoadNext (path);
@@ -711,7 +726,7 @@ ClazzLoader.loadScript = function (file) {
711726
};
712727
script.onload.path = file;
713728
/*
714-
* Fore Firefox/Mozilla, no related *.js will result in errors.
729+
* For Firefox/Mozilla, unexisted *.js will result in errors.
715730
*/
716731
script.onerror = function () { // Firefox/Mozilla
717732
this.onerror = null;
@@ -744,6 +759,12 @@ ClazzLoader.loadScript = function (file) {
744759
var fhs = ClazzLoader.failedHandles;
745760
var fss = ClazzLoader.failedScripts;
746761
var state = "" + this.readyState;
762+
763+
var local = state == "loading"
764+
&& (this.src.indexOf ("file:") == 0
765+
|| (window.location.protocol == "file:"
766+
&& this.src.indexOf ("http") != 0));
767+
747768
// alert (state + "/" + this.src);
748769
if (state != "loaded" && state != "complete") {
749770
/*
@@ -768,7 +789,12 @@ ClazzLoader.loadScript = function (file) {
768789
};
769790
fun.path = path;
770791
// consider 30 seconds available after failing!
771-
fhs[path] = window.setTimeout (fun, 15000);
792+
/*
793+
* Set 1s waiting in local file system. Is it 1s enough?
794+
* What about big *.z.js need more than 1s to initialize?
795+
*/
796+
var waitingTime = (local ? 500 : 15000); // 0.5s : 15s
797+
fhs[path] = window.setTimeout (fun, waitingTime);
772798
return;
773799
}
774800
if (fss[path] == 1) {
@@ -779,8 +805,8 @@ ClazzLoader.loadScript = function (file) {
779805
window.clearTimeout (fhs[path]);
780806
fhs[path] = null;
781807
}
782-
if (state == "loaded" && !ClazzLoader.isInnerLoaded) {
783-
if (fss[path] == null || fss[path] == 0) {
808+
if ((local || state == "loaded") && !ClazzLoader.isInnerLoaded) {
809+
if (!local && (fss[path] == null || fss[path] == 0)) {
784810
// silently take another try for bad network
785811
fss[path] = 1;
786812
// log ("reloading ... " + path);

0 commit comments

Comments
 (0)