Mink Machine

Media queries and JavaScript

Mobile development and responsive design are all the rage these days and media queries are mentioned everywhere. It’s a CSS3 extension of the media types frequently used in HTML4 and CSS2. The following (very simplified) example hides a sidebar if the browser device has a max width of 500 pixels.

@media (max-device-width: 500px) { .sidebar { display: none; } }

This is of course only the tip of the iceberg. There are tons of resolutions and variations to consider (for instance have a look at Andy Clarke’s Hardboiled CSS3 Media Queries), media queries are not supported by IE8 or older (live with it) and so on. But when used correctly, media queries can be a powerful tool.

However, media queries are indeed a nice asset when it comes to CSS, but unfortunately they will not prevent the browser from downloading many other things which may be superfluous on mobile devices.

Since many external scripts are large, this could be a problem. For instance, the minified and Gzipped version of JQuery is about ten times smaller in filesize than the regular version. It could also download a lot of images which may be unused on certain devices.

It would be nice to have a media query equivalent for JavaScript and other resources. There are some work-arounds, such as the one described by Peter-Paul Koch in Combining media queries and JavaScript, but I hope this area will improve in the future.

Related posts

Comments

No comments yet.

Post a comment

Your email address will not be published. Required fields are marked *

Featured stories

Road trip across the American Southwest

"We drove along Route 6, Route 66 and Route 666. If there was a Route 6666, we must have missed that turn."

On the Trans-Siberian

"Since the toilets were locked during the seven hour stop, we had to bribe the provodnitsas to use the facilities. Then came the Mongols."

Wazzup in Vaduz

"Vaduz Castle is overlooking the town from a hill, a short walk from the center. It’s really a postcard view with the alps in the background, which I’m sure the prince enjoys as he sips his morning coffee while towering above his loyal subjects."

Vineyards of southern France

"Not far from Sauternes is the village of Saint-Émilion, also a famous wine region but what got me hooked was their impressive limestone caves."

Roaming through Banff

"Even though the main town is surrounded by mountains with names such as Sulphur Mountain, it is as far away from Mordor as one could imagine."

Reliving history in Washington D.C.

"As I entered the heavily guarded Rotunda in the center, some of the most famous documents in the world laid before me."

Instagram