October 25, 2010

Modernizr on the server-side

The modernizr-server library is a way to bring Modernizr browser data to your server scripting environment.

There are a host of emerging techniques for adjusting web content to suit different types of browsers.

The current vogue seems to be to do as much of it as possible on the client-side: media queries, progressive enhancement, adding CSS body classes, and so on.

These are all cool, and hit a resonance with those who deal entirely with the front-end of a web site, and who prefer CSS (and a little Javascript) to Python, Ruby, PHP and the like.

In my opinion, this approach won’t always cut it. I’ve already pointed out that the users of radically different devices might want downright different things. Sometimes the differences between browsers are just too great to be able to deal with once the page has reached the client. And dealing with structural changes to a site’s information architecture based on browser capabilities gets messy, fast.

(Imagine if my site had a conditional a ‘photo upload’ feature that I wanted to place in the site’s menu for mobile devices that supported it. Do I have to feature test <input type=’file’> on every page, simply so I can add or remove nodes from the menu’s DOM? Ugh.)

So anyway, sometimes it’s far better to have had the server emit the best content in the first place – or at least as close as possible.

With this in mind, I’ve a new project called modernizr-server.

Modernizr itself is a great way to find out about your user’s browser capabilities. However, you can only access its API on the browser itself, which means you can’t easily benefit from knowing about browser capabilities in your server logic.

To address this, the modernizr-server library is a way to bring Modernizr browser data to your server scripting environment. For example, in PHP:



    print 'The server knows:';
    foreach($modernizr as $feature=>$value) {
        print "<br/> $feature: "; print_r($value);


The server knows:
canvas: 1
canvastext: 1
geolocation: 1
crosswindowmessaging: 1
websqldatabase: 1
indexeddb: 0
hashchange: 1

Exactly the same feature detection is available through this (PHP) API on the server as is available through the (Javascript) API on the client.

Currently, there is only a PHP implementation of the server-side API, but other languages would be easy enough. Stay tuned to the project for more (and let me know what might be a priority, or fork!).

For instructions on how to use, and information about how it works, you’re encouraged to consult the readme. Also this is a young project, so please use in high-traffic production environments with due caution.

Your feedback is welcome! Hope it’s helpful.

Comments (216)

  1. September 15, 2015
    toy story said...

    Do you have any video of that? I’d care to find out some additional information.

  2. September 16, 2015

    Hi! I know this is sort of off-topic however I had to ask. Does running a well-established website such as yours require a large amount of work? I’m brand new to blogging however I do write in my journal everyday. I’d like to start a blog so I can share my personal experience and views online. Please let me know if you have any kind of suggestions or tips for brand new aspiring blog owners. Appreciate it!

  3. September 18, 2015
    anapolon tips said...

    it is recommended to save Anadrol treatments and pills at a controlled room temperature of 20° to 25°C (68° to 77°F) with tours
    authorized to 15° to 30°C (59° to 86°F).

    my webpage – anapolon tips

  4. September 21, 2015

    My developer is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using Movable-type on several websites for about a year and am concerned about switching to another platform. I have heard excellent things about blogengine.net. Is there a way I can transfer all my wordpress posts into it? Any help would be really appreciated!

  5. September 22, 2015

    First off I want to say awesome blog! I had a quick question which I’d like to ask if you do not mind. I was interested to know how you center yourself and clear your head before writing. I’ve had difficulty clearing my mind in getting my ideas out. I do take pleasure in writing but it just seems like the first 10 to 15 minutes tend to be lost simply just trying to figure out how to begin. Any ideas or tips? Kudos!|掲示板}

  6. September 23, 2015
    เย็ด said...

    Hi, I ԁo bеlieve thiѕ is an excellent web site. I stumbledupon it 😉 I’m going to revisit yet again since i have bookmarked іt.
    Money and freedom is the best way to change, may you be rich and continue to help other people.

  7. September 30, 2015

    Halotestin will be north america what happens in other countries,
    this is especially true Mexico as a pharmaceutical readying including
    through market shops.

    Here is my webpage … best fitness halosim

  8. October 3, 2015
    เย็ด said...

    Hey! Would үou mind if I share your blog with my myspace gгoup?
    There’s a lot of people that I think wօuld really appreciate үour ϲontent.
    Plеаse let me know. Thanks

  9. November 10, 2015

    Thanks in support of sharing such a fastidious idea,
    paragraph is fastidious, thats why i have read it fully

  10. December 19, 2015
    Ezekiel said...

    I can see that there are two types you might not blog about.
    They are ‘determining details’ and ‘determining writer’s

  11. February 26, 2016

    Knowledge present that social homogenization is displaying up in online courting platforms by racial preferences and the proliferation of niche courting
    websites, even as the rate of online daters who say they strongly choose to this point someone
    of their own race” decreases.

  12. February 28, 2016

    When I initially coommented Iclicked tthe “Notify me when new comments are added” checkbox
    and now each time a comment is added I gett three e-mails with the same comment.
    Is there any way you can remove me from that service?
    Bless you!

    Here iss my web site :: cleaning machines

  13. March 14, 2016
    bing said...

    Hello colleagues, pleasant article and pleasant arguments commented here,
    I am genuinely enjoying by these.

  14. April 16, 2016

    Pretty! This has been an extremely wonderful article.

    Thank you for providing this information.

Leave a Reply