I have a site where the desktop version shows a sidebar containing 10 to 20 small images. Until now, on mobile devices, this sidebar has simply been hidden with display: none, which is the least effective solution, since all the images will be uploaded anyway.
Now I'm wondering how best to disable the sidebar completely on mobile devices (without using a separate AJAX request).
The best solution I could think of is the following:
- Enter the HTML of the sidebar into a JavaScript variable
- check device width by checking media request using javascript (e.g. using
Modernizr.mqor so) - If this test gives immobile device, write the contents of the variable in the DOM, for example, using
innerHTML, jQuery.append, jQuery.prependor similar
I know that RWD performance can sometimes be a very complex topic and that the most effective solution is often not obvious. So can anyone think of a better solution than the one presented above?
source
share