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 (144)

  1. June 11, 2014
    over-blog.com said...

    If you wish for to improve your experience simply keep visiting this web page and be updated with the newest gossip
    posted here.

    my web page – anz home loan calculator (over-blog.com)

  2. June 11, 2014

    For most recent information you have to pay a visit the web and on the web I found this
    website as a best web site for latest updates.

  3. June 12, 2014
    Lupita said...

    Hi, I think your site might be having browser compatibility issues.

    When I look at your blog site in Ie, it looks fine but
    when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that,
    amazing blog!

  4. June 13, 2014
    Maxine said...

    My Partner And I not too long ago set up our steam
    shower unit, the best thing i’ve decided to buy in a while,
    the children and friends and family like it so much, can not
    see us heading back to conventional showers anymore

    my web page :: steam shower enclosures – Maxine -

  5. June 13, 2014

    A fascinating discussion is worth comment. I do think that
    you should publish more on this subject, it may not be a taboo matter but generally people do not discuss such topics.
    To the next! Best wishes!!

  6. June 14, 2014

    You really make it seem so easy with your presentation but
    I find this matter to be really something which I think I would never understand.
    It seems too complicated and very broad for me.

    I’m looking forward for your next post, I will try to get the hang of it!

  7. June 15, 2014
    Valentina said...

    I have read so many content concerning the blogger lovers but this
    article is actually a good post, keep it up.

    Here is my homepage: 1200 microsoft points (Valentina)

  8. June 15, 2014

    Really like all these steam showers

    My webpage; steam shower spares

  9. June 15, 2014

    I read this paragraph fully on the topic of the difference of most recent and previous technologies,
    it’s remarkable article.

    Feel free to surf to my blog post criminal law cases in Warwick RI

  10. June 15, 2014
    Beatrice said...

    Epic post!

  11. June 16, 2014

    The leading plastic surgery clinic in Sydney
    specializes in offering all types of cosmetic surgery including Face lift, otoplasty, Rhinoplasty, Scar – Revisionn, Fat injection and Eyelid surgery.
    Treatments for Treacher Collins syndrome commonly require surgery to remove the area in which blockage occurs.

    With an type of plastic surgery, there will be a recovery process.

    Feel free to visit my weblog: more articles by amanda

  12. June 16, 2014

    Hi, this weekend iss pleasant for me, since this time i amm reading this
    wonderful informative post here at my residence.

  13. June 17, 2014

    Geologists find the Southern Central part of Death Valley National Park at the Amargosa Chaos be
    the most interesting in the world for understanding the process of extensional
    tectonics: the growth of land through fault movements. The diligent property manager goes
    room by room, item by item, from floor to ceiling, both indoors and
    out, and inspects, tests, photograghs, and documents the condition of
    the unit. Choose the company that has a long history of offering high quality courses.
    Characteristics of the office can be an investment, but in my opinion, this property does not qualify.
    In the construction world, water-resistant wall board is more commonly called “green board”.
    You will not require to make reservations in advance until you want to,
    and if your flight arrives late or is delayed you don’t need
    to be concerned about regardless of whether your journey is waiting for you when you are ready to leave the airport.
    It is mostly practiced in middle America, and now even some of
    the major carriers are getting away with rental rates that are below
    fair market value. Many of the same people
    who previously invested in residential real estate are moving in the
    purchase of commercial property as they see the current market conditions as the creation of an appropriate time to make this transition upwards.

    This trend will likely to continue to perform
    will into the predictable future. Once you are sure that they represent value for money
    you can go ahead and purchase them now and sit back to wait
    for the property market to pick up again.

    my weblog; real estate lookup

  14. June 17, 2014

    Poste actuel :Global Product Manager, Hotel OfferCarlson Wagonlit TravelPoste pr :Marketing Manager Global ProductsCarlson Wagonlit TravelEcole : Essec66 personnes

  15. June 17, 2014

    Frontline commando at its best. Game simulates warfare on the modern battlefield with a modern feel.
    Suppose you prefer to shoot your antagonists from distances or to snipe them from hundreds of meters. Heed the call of duty and go on a shooting spree as you will become the apex sniper, murdering cosmic bugs like zombies in the forest. It is almost like Dead Trigger just featuring space enemies. Unknown to man previously, kind discovered on the surface of the Moon. Armaments that will come to your hands are not distant and numerous, but they are acceptable enough to defeat any challenge you’ll ever find. In the midst of the red sands of Mars fps experience shall be extensive and fascinating.
    Survive the endless rush of interplanetary horror, waste the space aliens to their death and witness them disintegrate and perish. Only the best feats of modern combat shall change the flow of this interplanetary war. Done on the unity mobile game source code, this edge of tomorrow sim will bring you the impression of actually having the hard shadowgun in your fingers. Diverse dead in space shall impact you. Countless sniper shooters have perished before you so this modern battlefield can deliver you greatly amusing and enchanting torment anytime. Download it fast and become the greatest shadowgun rifleman, while besting the modern warfare combat. But you have to know that this ain’t Deer Hunter – there is real blood and true sweat because you’ll be battling the battle for mankind, as the fight on the alien battlefield shall determine the fate of the universe. The far cry of your call of duty will push you to your limits, as the cosmic terror shall bring you tests and woe of large ammounts. Ready your shadowgun and lock and load; put your hand dead on the trigger and roll up the muzzle of your rifle of choice. Exclusively today free modern combat.
    This android aplication get on the android market for your enjoyment.

  16. June 17, 2014

    For latest news you have to visit world wide web
    and on internet I found this site as a finest web site for most recent updates.

    my web blog … DUI attorney in Pawtucket RI

  17. June 17, 2014

    My mind was blown when I’ve first seen this awesome piece of action. Become a frontline commando with your pistol blazing, or snipe the zombie demons from huge distances. Seeing uncountable undead bugs dead, trigger continually kicking as I was launching my shadowgun and tossing explosives around. All using only your touch screen. Freshest phone game from a one of the best game studios, presenting such magnificent and breathtaking baddies that I’m still stunned and appaled.
    Our health gets to be customized which is the only thing that lets us proceed even deeper into this science fiction nightmare.
    Only the best exploits of modern warfare combined with an itchy trigger finger will let you to win over the undead bugs. Great graphics encourage you to follow your call of duty. Combat in modern style your terror when traversing future human locations and throwing barrages of bullets from your shadowgun, become the ultimate mobile frontline commando, murdering millions like an android.
    Ominous lead character reminisced me of the old Doom PC game, though Combat Trigger: Modern Dead 3D has several more gameplay features.
    Superb gameplay! Modern warfare gets blended with dark and depressed futurism, where deep space exploration gave us only indescribable dismay of having Terra occupied by dead zombie bugs. Billions of them, actually. All hungry for our blood and our homes!

  18. June 18, 2014
    teptich said...

    I love what you guys tend to be up too. This type of
    clever work and reporting! Keep up the very good works guys I’ve
    included you guys to my blogroll.

  19. June 18, 2014

    There’s definately a great deal to know about this
    issue. I love all the points you made.

  20. June 19, 2014

    Very quickly this website will be famous among all blog users, due to it’s fastidious content

    Review my web-site … war Thunder golden eagles Hack Download

  21. June 21, 2014

    Hi i am kavin, its my first occasion to commenting anyplace, when i read
    this post i thought i could also create comment due to this sensible piece of writing.

  22. June 22, 2014
    Sara said...

    It’s wonderful that you aree getting thouhts from this piece of
    writing as well as from our argument mmade at this place.

    My webpage; team site traffic reviewed – Sara -

  23. June 24, 2014

    The World Wide Web is an important marketing medium and to gain success
    in this arena a marketer should have well planned online
    marketing strategy. As with any online marketing activity, keep the message short,
    sweet and direct and be sure to include the necessary contact information needed to send in a referral.
    Instead target and focus your internet marketing campaign towards
    your target audience and target market to achieve more success.

    Feel free to surf to my webpage :: vacuum cleaner (https://www.openstreetmap.org/user/robotvacuumcleaner)

  24. June 25, 2014
    Stepanie said...

    Aw, this was an incredibly good post. Spending some time and actual effort
    to make a superb article… but what can I say… I
    procrastinate a lot and never manage to get nearly anything done.

    Feel free to visit my webpage; clash of clans hack (Stepanie)

  25. June 26, 2014

    Employers seem to be taking a greater and greater interest in their
    employees’ Facebook posts. What seemed to be only for teens is now proving
    extremely useful not only for individuals, but also businesses looking to connect with
    customers. Let’s say that you attend networking
    events on a regular basis, you probably have tons of business cards on your selves or on a shoes box, and are just not doing anything with them.
    Yet posting data online is the same as shouting your deepest secrets at the top of your lungs while simultaneously spray-painting what
    you’re saying on a wall where the message will never be taken off or painted over.
    Thus far the site has received considerable press and, though figures on recent sign ups and current user
    numbers are not yet available, it is thought that
    the network has enjoyed relative success
    thus far. (Here’s an article with more on choosing the right agency, released March 19.
    Why would you think an international corporation like Facebook would care about you.
    Businesses of all sizes should be advertising for customer response
    and creating content that raises brand awareness. The 100 million users of Linked – In constitute
    a very lucrative market. Social media does not have a one-size-fits-all strategy.

    Have a look at my website delray beach social media marketing advantages

  26. June 29, 2014

    Was actually looking for just a traditional shower enclosures
    when i found this web site, didn’t have any idea there
    was such a thing as a ‘steam shower enclosure’,
    incredible, may very well just have to have
    one

    Check out my web page; insignia steam Shower retailer

  27. June 29, 2014

    My brother suggested I may like this web site. He used to be totally right.

    This put up actually made my day. You cann’t imagine just
    how a lot time I had spent for this information! Thank you!

  28. June 29, 2014

    What do you do if you opt to divorce your husband on account of
    his being hooked on Internet sexually graphic. He gets liberal visitation and from now on your sons or daughters are being
    exposed to Internet porno but now entirely from the guidance?

    It is a common problem. You see your mate has an being hooked
    on porn and also extreme fetish adult which. You come to the difficult decision to keep him but now he has unsupervised visitation with the minor children and you dread the children are exposed to often the perverted
    materials.

    my site :: brazzers accounts [getbrazzersaccountsfree.wordpress.com]

  29. July 1, 2014
    etv.s-lines.net said...

    Do you mind if I quote a few of your articles as long as I
    provide credit and sources back to your site? My website is in the very same niche as yours and my visitors
    would genuinely benefit from some of the information you present here.

    Please let me know if this ok with you. Appreciate it!

  30. July 1, 2014

    This post is really a nice one it helps new internet users, who are wishing for blogging.

  31. July 1, 2014
    tv advertising said...

    That is a very good tip especdially to those fresh to the
    blogosphere. Brief but very accurate info… Thanks for
    sharing this one. A must read post!

    Here is my web-site :: tv advertising

  32. July 16, 2014
    Octavio said...

    Quality articles or reviews is the key to be a focus for the people to visit the website, that’s what
    this website is providing.

  33. July 21, 2014

    The betting bot was talked about and used on different take a look at elsewhere, but since this isn’t obtainable commercially or no standard settings are available, it might not be a real representation of its results.
    i – Book allows you to download and read everything from
    best sellers to classics right on your i – Pad. People are eager to carry their
    i – Phone while going for their morning walk and yoga session.

  34. July 21, 2014

    Hi there, just became alert to your blog through
    Google, and found that it’s truly informative. I’m gonna watch out for brussels.
    I’ll be grateful if you continue this in future. A lot of eople will be benefited from your writing.
    Cheers!

    My web blog – hair loss remedies dr oz

  35. July 23, 2014

    A property may also need to be appraised if it is a subject of litigation, such as
    in Probate or Divorce Court. Whether you want buy a property
    or want to sell your wake forest real estate contact
    local real estate agents, property dealer or place your listing on the internet and get found by thousands of people it is
    one of the most effective and fast way to buy and sell the
    property in a desired area. With stable property rates, opportunities for growth and a metropolitan population,
    developers and designers of national and international repute too are setting anchors
    in Pune.

    Check out my site asheville luxury homes

  36. July 23, 2014
    Submit A Game said...

    An interesting discussion is worth comment. I do think
    that you should write more on this topic, it might not be a taboo
    subject but usually people do not talk about these topics.
    To the next! All the best!!

  37. July 23, 2014
    silenor said...

    I have read so many articles about the blogger lovers except this article is actually a pleasant piece of writing,
    keep it up.

    my web blog silenor

  38. July 25, 2014
    Marty said...

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for
    quite some time and was hoping maybe you would have some experience with
    something like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to your new
    updates.

  39. July 28, 2014

    Hello there! Quick question that’s completely off topic.
    Do you know how to make your site mobile friendly?

    My blog looks weird when viewing from my iphone4.
    I’m trying to find a theme or plugin that might be able to resolve this
    issue. If you have any suggestions, please share.
    With thanks!

  40. July 28, 2014

    create a mobile friendly version, create your fully customized mobile site, start selling websites.
    Just for follow the link : http://todayone.com.au/

  41. July 31, 2014
    Cheri said...

    Fourteen-hundred craftsmen worked more than three
    times the growth of new towns. A growing middle class means more discretionary spending money, which nobody reported to the NSS, but poor performance of the farm sector owing to weak monsoon retarded overall growth.

    Feel free to surf to my webpage: Riad Marrakech Morocco three palms
    - Cheri -

  42. August 1, 2014

    Hmm it seems like your site ate my first comment (it was super
    long) so I guess I’ll just sum it up what I wrote and say,
    I’m thoroughly enjoying your blog. I as well am an aspiring blog writer but I’m
    still new to the whole thing. Do you have any recommendations
    for beginner blog writers? I’d genuinely appreciate it.

  43. August 1, 2014
    ShockingDaily said...

    Attractive section of content. I just stumbled upon your web site and in accession capital
    to assert that I get actually enjoyed account your blog posts.
    Any way I’ll be subscribing to your augment and even I achievement you access consistently
    fast.

  44. August 1, 2014
    Cleta said...

    Alexander’s book may be the New York Times #1 bestseller for 23 weeks.
    The touchscreen technology itself can be responsive, navigation is easy, and the menu icons are big
    enough that users should be able to work with easily.
    The first six months of the year have been crazy inside my
    world.

Leave a Reply