0

I am working on developing Responsive Web application and I wish to load all the content on my desktop site but I want to prevent the HTTP request to send when users access web applications from mobile devices to I can improve my website performance.

If I use style=" display: none;" or style=" visibility: hidden;" this will not display the content but it loads on my website so it will not improve my web site performance.

So I want a solution that HTTP request must not send which I don't want to display the content on my mobile device website view.

Akshay Jain
  • 790
  • 1
  • 7
  • 21

1 Answers1

0

You should use redirects and headers This is just example if you are using PHP web server:

index.html (from here):

<script>
function detectmob() { 
 if( navigator.userAgent.match(/Android/i)
 || navigator.userAgent.match(/webOS/i)
 || navigator.userAgent.match(/iPhone/i)
 || navigator.userAgent.match(/iPad/i)
 || navigator.userAgent.match(/iPod/i)
 || navigator.userAgent.match(/BlackBerry/i)
 || navigator.userAgent.match(/Windows Phone/i)
 ){
    window.location="action.php?mob=true";
  }
 else {
    window.location="action.php?mob=false";
  }
}
detectmob();
<script>

action.php:

<?php
if(!$_GET["mob"]){
    define("var","myvar");
    require("yourfile.php");
}else{
    echo "Mobile device detected!";
}?>

yourfile.php:

<?php
if(!defined("var")){echo "no entry";return;// var not defined hence mobile device
}?>
<!-- not return hence not mobile device -->
<!-- begin other codes --->

Note: I am not guaranteed that page will load on only desktop device. Because PHP or back end languages doesn't really know that device is Desktop or Mobile.

Because of redirect are from simple HTML page, it can be changed by any person that editing DOM element or Direct specification of URL. Hence your idea of loading website on only desktop device will not perfect from all

Ritesh Khandekar
  • 3,885
  • 3
  • 15
  • 30