How to load or not a JS script (into the head section) based on screen resolution?

前端 未结 6 1393
眼角桃花
眼角桃花 2020-12-20 02:36

on a website, I have these lines on the tag

  
  

        
6条回答
  •  余生分开走
    2020-12-20 03:09

    Check on Javascript your screen width and then append your script like this.

    if(window.innerWidth > 950){
        var s = document.createElement("script");
        s.type = "text/javascript";
        s.src = "http://www.domain.com/js/jquery.min.js";
        $("head").append(s);
    }
    

    I hope it helps.

提交回复
热议问题