PHP, JavaScript – Is it right to detect screen-width by redirecting header

Saturday, October 17, 2015

I am using the following JavaScript to detect the screen-width and use it as a constant across my template files through conditional statements to display / not-display portions of my site. While it has nothing much to do with my questions, but just in case… Yes I am using WordPress.

  function getLayoutWidth() {            if (isset($_GET['width'])) {            // output the geometry variables            // echo "Screen width is: ". $_GET['width'] ."<br />\n";            //$layout = $_GET['width'];            define( "SCREEN_WIDTH", $_GET['width']);          } else {            echo "\n";            echo "  location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"                          . "&width=\" + screen.width;\n";            echo "\n";            exit();          }      }    

Important :

  1. Other techniques are like…… Let's assume if my site is 2MB in size, it will still load 2MB of content and then hide 1.5MB of it on mobile devices by using CSS properties like display:none; Whereas I don't want that template part to load itself, thus not needing to hide anything.

  2. I am not looking to load an entire JavaScript library like jQuery or so to do this because location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}". "&width=\" + screen.width; is the only JavaScript in my entire site. Rest everything is pure PHP, HTML and CSS based. I even disabled jQuery of WordPress in the front-end template.

My questions :

  1. Is this a good / correct way to do from SEO stand point?

  2. My URL is displayed as example.com/my-product-category/my-product-name/?width=1440 Is there a way to remove /?width=1343 and display just example.com/my-product-category/my-product-name part?

Please feel free to suggest any other methods also if this is not good / correct.


Filed under: php

0 comments:

Post a Comment