title: Add or Remove HTML code on Windows Resize
body: <p>I'm working on a responsive website. I'm using CSS Media Queries and Adaptive Images (http://adaptive-images.com/) to render each page correctly on different devices.</p>
  
  <p>My problem is that some elements are downloaded by the browser even if there are hidden! For instance, a  element with the property {display:none;} is downloaded despite the fact that I don't want it.</p>
  
  <p>So, here is my question: is there a way to add or remove HTML code depending on the device's screen-size?</p>
  
  <p>By reading the code of  "Adaptive Images" script, I saw they used a cookie, which stores the screen-size value. </p>
  
  <pre><code>    &lt;script&gt;
      document.cookie='resolution='+(window.innerWidth)+'; path=/';
      window.addEventListener("resize", function() {
          document.cookie='resolution='+(window.innerWidth)+'; path=/';
      }, false);
      &lt;/script&gt;
  </code></pre>
  
  <p>So, I tried to read this cookie with a PHP function:</p>
  
  <pre><code>&lt;?php 
      $fallback_res = 481; 
      $res = !empty($_COOKIE['resolution']) ? $_COOKIE['resolution'] :  
      $fallback_resolution; // Get the viewport resolution in $res variable
  ?&gt;
  </code></pre>
  
  <p>It allows me to write a very useful PHP condition :</p>
  
  <pre><code>&lt;?php if(isset($res) AND $res &gt;= $fallback_res) // if viewport &gt;= 481px
  {
          echo '&lt;video&gt;...&lt;/video&gt;'; // Display the video 
  }
  else { //if the screen is smaller
      echo ''; // Echo something else 
  }
  
  ?&gt;
  </code></pre>
  
  <p>It work very well. If the viewport is &lt; 481px, the video is not downloaded. If the viewport is > 481px, the video is downloaded. But it only works, on page load!  If I load the page with a 480-wide-opened-browser (=video not loaded), and then resize my browser to higher resolution, there is a big hole in the middle of the page. </p>
  
  <p>What I need is to reload some part of the code on window resize. (Each time I resize the browser window, I want the $res condition to be updated automatically, and the following code as well)</p>
  
  <p>Thanks.</p>