0

I have two scripts and stylesheet, one is for mobile device and another for pc.

I don't want to load the CSS stylesheet and JS file when user access from mobile or tablet devices

<script type="text/javascript">
var ismobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));

    if(!ismobile) document.write('<script src="js/PCDemo.js"></script>');
    if(!ismobile) document.write('<link href="css/PCDemo.css" rel="stylesheet" />');

    if(ismobile) document.write('<script src="js/MobileDemo.js"></script>');
    if(ismobile) document.write('<link href="css/MobileDemo.css" rel="stylesheet" />');

</script>

I found this stackoverflow link

Is it good way to load the file?..

Community
  • 1
  • 1
Liam neesan
  • 2,282
  • 6
  • 33
  • 72
  • see here the answer's explaination:https://stackoverflow.com/questions/10508669/tell-html-doc-not-to-load-js-if-mobile-device – לבני מלכה Oct 07 '18 at 11:53
  • @לבנימלכה That answer is almost same as mine. As well as I don't want to ignore it by screen size. Because I will not change css and js design even user reduce the browser screen – Liam neesan Oct 07 '18 at 11:58
  • I mean see those answer there are explainations about `Is it good way to load the file?..` as I see there Your files won't load only in desktop(or whatever you want) – לבני מלכה Oct 07 '18 at 12:01

0 Answers0