This is what I used at the end. It uses a bit of jquery, but you can convert it from jquery if you need to.
First configure html as follows:
<link class="matchmedia" data-href="static/css/mobile.css" data-rel="stylesheet" data-max="739">
Data-max is our way of reporting the functions below to check the maximum width. When a function is called, it will look for elements that have a class called "matchmedia", and then check the restrictions specified in data-max and data-min, and if they pass these tests, it will make a copy of any attribute whose name begins with "data-" and copy the value. And hey presto we have a conditional load.
ws.width = <your favourite method of getting the width>; function mediaMatchHTML() { $(".matchmedia").each(function(){ var min = this.getAttribute("data-min"); //in pixels var max = this.getAttribute("data-max"); //Check condition if ((min === null || ws.width >= min) && (max === null || ws.width <= max)) { for (var c=0; c<this.attributes.length; c++) { var name = this.attributes[c].name.slice(5); if ("data-"+name == this.attributes[c].name) { //is this lined up for conversion? this.setAttribute(name, this.attributes[c].value); } } } }); }
Matt parkins
source share