Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit afb44be

Browse files
committed
add exists cache registry and force recheck param
1 parent bfb7839 commit afb44be

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

js.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$js - asynchronous module definition framework
33
or just simple lightweight javascript dependencies manager
44
5-
@version 3.9
5+
@version 4.0
66
@link http://github.com/redcatphp/js/
77
@author Jo Surikat <jo@surikat.pro>
88
@website http://redcatphp.com
@@ -493,7 +493,8 @@
493493
scripts[m][u].push(c);
494494
};
495495

496-
var onExists = function(s,y,n,sync){
496+
var existsRegistry = {};
497+
var onExists = function(s,y,n,sync,force){
497498
sync = sync?true:false;
498499
if(s instanceof Array){
499500
s.reverse();
@@ -504,6 +505,13 @@
504505
eval(ev);
505506
return;
506507
}
508+
if(!force&&typeof(existsRegistry[s])!='undefined'){
509+
if(existsRegistry[s])
510+
y();
511+
else
512+
n();
513+
return;
514+
}
507515
var url = getSrc(s);
508516
var httpRequest;
509517
if(w.XMLHttpRequest){
@@ -521,9 +529,11 @@
521529
httpRequest.onreadystatechange = function(){
522530
if(httpRequest.readyState==4){
523531
if(httpRequest.status!=404){
532+
existsRegistry[s] = true;
524533
$js(s,sync,y);
525534
}
526535
else{
536+
existsRegistry[s] = false;
527537
n();
528538
}
529539
}

0 commit comments

Comments
 (0)