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:

<?php

    include('modernizr-server.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 (176)

  1. August 9, 2014

    I am a plugin coder for wordpress. I crafted a plugin that is able
    to scrape web surfer’s email addresses in your database without
    having to use their contact. I’m in need of ‘beta’ evaluators and also, since
    you’re receiving immense amounts of internet site visitors, I am checking out both you and your web-site.
    Do you think you’re intrigued?

  2. August 10, 2014

    This artificial fragrance, alcohols will create pain and skin irritation. He still couldn’t believe that he was working for the woman everyone referred
    to as Mrs. Cheaper versions are less likely to coat
    evenly or have colors that do not blend well with a variety of skin tones.

    Have a look at my web-site … spray tanning bar equipment and supplies

  3. August 12, 2014

    I’m not certain where you’re getting your info, but great topic.
    I must spend some time studying more or understanding more.
    Thank you for wonderful information I was searching
    for this info for my mission.

  4. August 12, 2014

    Heya just wanted to give you a brief heads up and let you
    know a few of the pictures aren’t loading properly.
    I’m not sure why but I think its a linking issue.
    I’ve tried it in two different web browsers and both show the same outcome.

  5. August 12, 2014
    No Sick Fish said...

    Thanks fօr the auspicious writeup. It in fact useԁ
    to be a amusement account it. Glance complex to far introduced agreeable from you!

    However, hߋw could we keep in touch?

    Have a looҝ aat my blog No Sick Fish

  6. August 12, 2014
    โกดัง said...

    If you happen to be the proud owner of a RV, then there will be no
    need to worry about finding space for parking the magnificent metal machine because RV storage units are
    also available in warehouses. Our expert marketing, professional service, North American wide network of customers, along
    with free professional website listing and assistance for your warehouse racks
    will help your company both save and make money on the sale of
    your warehouse racking. Thus car storage, RV storage and boat storage becomes easy for vehicle owners.

  7. August 13, 2014

    Hi there to all, it’s actually a pleasant for me to pay
    a quick visit this site, it contains precious Information.

  8. August 16, 2014

    What’s up it’s me, I am also visiting this website daily, this
    website is actually fastidious and the people are truly sharing nice thoughts.

    Look into my weblog … chicken coop ideas

  9. August 16, 2014

    Simply want to say your article is as surprising. The clarity
    in your post is just nice and i could assume you are an expert
    on this subject. Fine with your permission allow me to grab your feed to keep
    updated with forthcoming post. Thanks a million and please keep
    up the rewarding work.

  10. August 17, 2014

    Magnificent goods from you, man. I’ve understand your stuff previous to and you are just extremely fantastic.
    I actually like what you’ve acquired here, really
    like what you’re stating and the way in which you say it.
    You make it enjoyable and you still take care of to keep it sensible.
    I can not wait to read much more from you. This is
    really a great site.

    My blog post :: non surgical nose job nyc

  11. August 17, 2014

    Will you be one in the citizens of Los Angeles that are in want on the providers of a mover.

    Everyone wants to get free of these boring tasks of relocation. Since First Call Movers have
    been local movers, long distance movers and have carried out moving assignments for
    government agencies, retail companies yet others, they certainly know a thing
    much more about moving.

    Here is my web page; bestway moving and storage springfield mo

  12. August 18, 2014

    Farrah Fawcett’s famous pinup is probably the most iconic summer look in history.
    The truth of the matter is that there is always
    room for negotiation. What about the office parties many
    of us has to attend.

    Take a look at my site :: celebrity evening dress replicas uk

  13. August 18, 2014
    Web Page said...

    Pretty great post. I simply stumbled upon your weblog and wished to mention that I have really loved
    shrfing around your blog posts. In any case I will be subscribing to yopur feed and I’m
    hoping you write once more very soon!

  14. August 19, 2014

    I guess it is another attempt to stereotype conservatives as extremists (and
    liberals are not. Hear them out, seek first to understand,
    then be understood. The cast iron cylinder head was chosen for
    low cost and structural integrity.

  15. August 25, 2014

    I’m not that much of a online reader to be honest but your blogs really nice, keep it up!
    I’ll go ahead and bookmark your site to come back in the future.

    All the best

    Feel free to visit my web blog – unlock iphone 5 (thetimesofusa.com)

  16. August 27, 2014
    Frontenddev said...

    I think maybe a captcha might be in need here? The comments are amusing though.

    I am particularly interested in the topic of feature detection on the server side. I am personally a fan of Modernizr but am unable to use it in my work situation as we need something that has no-js support. For that reason we’re stuck doing horrible browser detection instead >.<

  17. August 27, 2014

    Very descriptive article, I loved that a lot. Will there be a part 2?

    My weeb pagte … breaking bad store uk

  18. August 28, 2014

    You will probably recognise some or all of these as some
    as used more than others with very great success in carp
    baits:. For instance at a time when anglers where sticking rigidly to the
    mantra of 3 to 5 milliliters of flavour, plus 1 to 2 milliliters of
    intense sweetener to a pound of base mix or more,
    as measured by 4 large eggs or 6 medium eggs as a basis of
    measurement, I tried other approaches and reaped big rewards against much
    more experienced anglers. A camera and photo album are another way for a family to record
    their boating trips.

    my weblog … deck vegetarian freezer meals

  19. August 29, 2014
    hcg diets said...

    Although HCG is only produced by females, HCG
    is an effective way to drop excess excess weight for the two
    genders. Each year multiple ideas of what will work in helping us lose weight fast, is tossed around the radio dial, internet,
    and television about as often as Nicolas Cage makes movies.
    There is also an eating regimen that you will have
    to follow very closely.

    my weblog; hcg diets

  20. August 30, 2014

    Thanks for finally writing about > Modernizr on the server-side

  21. August 31, 2014

    Very nice post. I just stumbled upon your weblog and wanted to say that I’ve truly enjoyed surfing around your
    blog posts. After all I will be subscribing to your rss feed and I hope you write again soon!

  22. August 31, 2014

    If you are concerned about staying motivated with an online program but don. The supplement actively makes the
    proper utilization of nutrients in the body and makes it more healthy and flexible.
    And they get frustrated because of it, and maybe keep going for a few more days and still they
    don.

    My homepage: where to purchase garcinia diet pills

  23. September 2, 2014
    hcg diet said...

    Howdy just wanted to give you a quick heads up and let you know a few
    of the pictures aren’t loading correctly. I’m not
    sure why but I think its a linking issue. I’ve tried it in two different
    internet browsers and both show the same outcome.

    My page: hcg diet

  24. September 7, 2014

    I do believe all of the ideas you have presented on your post.
    They’re really convincing and will certainly work. Still,
    the posts are too quick for starters. May you please prolong them a bit from next
    time? Thanks for the post.

    Here is my website: pawn shops online jewelry

  25. September 7, 2014

    The first phase, you can generate an exceptional amount of gluten can abc make the monthly wireless data
    plan, including handwritten and eail marketing campaigns that
    engage your people. He is committed to providing the necessary licenses and your revenue as you dole it out and about
    10- 30 million abc $13-$14 million from BlackBerry, iOS
    and Android.

  26. September 8, 2014
    coupon code said...

    constantly i used to read smaller content that as well clear their motive, and that
    is also happening with this paragraph which I am reading at this time.

Leave a Reply