Send Modernizr to the client before you construct your page's mark-up, use the test results on the server to decide what mark-up the device should get. This project builds on top of James Pearce's Modernizr Server, adding testing, localStorage, and making all test results available to the final client-side page as well. See James' original work …
JavaScript PHP
Pull request Compare This branch is 5 commits ahead of jamesgpearce:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
modernizr.js
LICENSE
README.md
index.php
modernizr-server.php

README.md

Modernizr-Server and -Client

James Pearce did a great job developing his "first cut" of Modernizr-Server. The first thing you should do if you decide to try-out this project is check-out his work, get to know what he's doing, and how it works. This project definitely builds on top of James' work.

tl;dr: James' version sends a minimal page to the client browser, runs all the Modernizr tests you ask it to run, stores the test results in a cookie, and refreshes the page. When the refreshed page sees the cookie, it pushes those values into a server variable that can be used to decide what mark-up to deliver back to the client for the user to view and use.

This project adds to James' work in the following ways:

  1. There are a series of tests that now run to make sure the Modernizr tests can run successfully (make sure the Modernizr JS file is available, whether cookies are available, etc.). If this process cannot complete successfully, it just delivers the intended page to the user, avoiding the possible infinite loop that was an issue previously.
  2. The Modernizr test results are retained in the client browser (including the <html> classes) so the tests don't have to be run again in the client browser. This allows you to also using them as initially intended, to make client-side decisions.
  3. An attempt is made to use localStorage to store those Modernizr test results, in order to reduce the cookie overhead, falling-back to cookies if localStorage is not available.

Demos:

  • Working Demo
  • With localStorage forced to not work (coming...)
  • With cookies forced to not work (coming...)
  • With localStorage and cookies forced to not work (coming...)

TODOs:

  • should the Modernizr cookie be pushed to a server variable & localStorage, to avoid cookies completely?? can that work and stsill avoid infinite looping?
  • test if !localStorage
  • test if !cookies
  • test if !localStorage && !cookies
  • test in all worthwhile browsers
  • document all results...