は、あなたがこのような3列のデスクトップのレイアウトを持っていると仮定します。
<body>
<div id="ad-1">
//javascript1 goes here
</div>
<div id="content">
//content goes here
</div>
<div id="ad-2">
//javscript2 goes here
</div>
</body>
そして、あなたがそのようなことを応答サイト作成したと仮定:あなたがロードしたくない
@media screen and (max-width: 1024px) {
#ad-1{ display: none; }
}
@media screen and (max-width: 768px) {
#ad-2{ display: none; }
}
をスクリプトが表示されていない場合はそれを解決する方法があります:
var ResponsiveScriptsLoader = {
onAdsReady: function() {
console.log('success');
},
addScripts: function(scripts, callback) {
for (var i = 0; i < scripts.ads.length; i++) {
this.include(scripts.ads[i].src, scripts.ads[i].selectorID);
if(i==scripts.ads.length-1) callback();
}
},
include: function(what, where) {
var deferred = new $.Deferred(), place;
var e = document.createElement('script');
e.onload = function() { deferred.resolve(); };
e.src = what;
place = document.getElementById(where);
if(place) {
place.appendChild(e);
}
return deferred.promise();
},
init: function(){
if(screen.width > 768){
if(screen.width > 1024){
this.addScripts({
ads: [
{
src: "http://ads.script1.js",
selectorID: "ad-1"
},
{
src: "http://ads.script2.js",
selectorID: "ad-2"
}
]}, this.onAdsReady);
} else{ // Screen size is between 769 and 1023
this.addScripts({
ads: [
{
src: "http://ads.script2.js",
selectorID: "ad-2"
}
]}, this.onAdsReady);
}
}
}
}
ResponsiveScriptsLoader.init();
条件付き読み込みとは別に、 urのJavaScriptファイル。私は[Chirpy](http://chirpy.codeplex.com/)がいいと聞いています。 – jhsowter
またはGoogleのクロージャーコンパイラ:http://closure-compiler.appspot.com/home –
@jhsowter - javascriptファイルはすでに縮小されていますが、Chirpyを教えてくれてありがとう - 間違いなくasp.netイントラネット私たちが持っているサイト。 – CYMR0