TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Sniff my browser: The Modernizr inadequacy

37 pointsby garethrabout 14 years ago

9 comments

JoelSutherlandabout 14 years ago
I have mixed feelings on Modernizr...but this post seems to be filled with a number of weak points.<p>First, the Modernizr file ends in ".js" I don't think anybody is fooled about how it works and what its consequences are.<p>Second, the advocated method of stying your site with Modernizr is to first make it look good assuming no "advanced features" exist and then progressively enhance. This ensures that the failure of Modernizr to load will leave you with what you started with. Given that the Modernizr classes are added to the root of your document this claim seems impossible:<p>"However, it also means there is a significant loss in the overall structure of specificity within your stylesheets, which could easily cascade unintended effects through to other elements."<p>Finally his core argument is that Modernizr violates the separation of concerns in front-end web development. This is true and something that you have to be willing to accept to use it.<p>His proposed alternatives are strange however. He suggests server-side browser sniffing, a bad idea as the article itself explains. Alternatively he suggests using CSS cascading, but this is a bit of a tautology since this is the problem Modernizr was designed to solve.<p>My personal opinion is that Modernizr is a bit of a kludge, but often the least ugly option available.
评论 #2556571 未加载
bruce511about 14 years ago
There is this constant tug-of-war going on for developers. On the one hand we want to provide the best possible experience to the end-user, and on the other hand we want to include as many people as possible.<p>The two forces are in competition with each other though, because very often the largest group of people are running older technology.<p>We can broadly divide the potential user base into 3 groups. Those "ahead" with a cutting-edge browser, those with a "modern browser" and those "left behind". Today we'd consider IE6 users and Windows Mobile 6 users as "left behind". We'd consider HTML5 in a late-version of Chrome to be "ahead". Not surprisingly though the vast majority of people are in the middle.<p>The key question seems to be "Is JavaScript in the mainstream?". I think the answer to that is yes. Even IE6 has Ajaxian capable JavaScript. So therefore is the user-experience, of the many, improved by using JavaScript, to the point where the "few" are sacrificed? In my opinion, yes.<p>Certainly the user experience is improved immensely with the use of JavaScript. The question then becomes whether it is better to service say 95% (<i>) of the market really well, or 100% of the market in a mediocre fashion? I would argue that the market does not reward mediocrity - and the 5% you have gained are the least likely to appreciate your effort anyway.<p>(</i>) pick whichever number here you prefer.<p>Take an average hotel website for example? It's certainly all-inclusive, but at the same time is horribly unusable. It has evolved since 1995, and it's still as awful as it was then. Does a hotel gain 5% more occupancy for making it all inclusive, or do they lose more than 5% for having a horrible interface?<p>Personally I don't believe any site is "all inclusive". Those primitive enough to include the bottom end, are too dull for the folk on the top end. So the real question becomes, would you rather have the top, or bottom demographic?<p>Bearing in mind that for the vast majority the decision to not have JavaScript support is completely their own?<p>Now of course every site has different considerations. But in my opinion the starting point for the discussion is "how much is that 5% worth?"<p>Will Modernizr make everyone happy all the time? Well, no. Then again, nothing will.
jsdaltonabout 14 years ago
Yeah, basically there <i>is</i> one shortcoming of the "Modernizr approach" to front-end development -- namely that you will end up treating clients who have JS disabled as though their browsers do not support a number of CSS features.<p>So with the old browser sniffing way, your Firefox 4 user will still get the shiny buttons and rounded corners even if he has no JS. With Modernizr, he'll (at best) get the watered down IE6 version with flat buttons and sharp corners, etc. At worst, if you're not doing progressive enhancement right and you've based critical functionality on one of the injected classes, you might cause some real problems for this user.<p>I guess I just see this as a limitation of Modernizr, and not a reason to throw out the baby with the bath water. I still love it and use it in all of my projects.
评论 #2556638 未加载
pkteisonabout 14 years ago
Tl;dr: Entire article is nothing but 'relying on js is bad'.<p>Author discounts modernized entirely because it only works with javascript. Suggests you can replace it entirely by tagging your html tag with an ie class using conditional comments (thereby relying on browser sniffing, after arguing that browser sniffing is terrible and doomed to fail) and the cascade in stylesheets.<p>I'm not convinced this gives a fair shake to the difficulty of getting graceful degredation right with just the cascade, and any author that says 'x is bad' then relies on x is clearly presenting an incomplete argument.
评论 #2556488 未加载
poinkabout 14 years ago
This post seems ridiculous. Modernizr is "bad" because it depends on JS, but the alternative solution suggested is to go back to user agent sniffing and just do it on the server side. I'd forgive the author for not knowing why user agent sniffing is a terrible idea, but it was covered in the post itself...
ramenabout 14 years ago
Modernizr does a lot of things, and creating CSS classes to mark the existence of features is just one of those things. Another thing that Modernizr does is allow you to style new HTML5 elements like &#60;section&#62;, &#60;header&#62;, etc. - I think that there is a similar issue here, and I'm really on the fence about it. Depending on the browser to execute Javascript so that CSS is able to style a new element seems risky, and for quite a marginal benefit. I guess people are just trying to make the future happen sooner, but it seems foolish to introduce an external dependency and scripting requirement just because &#60;header&#62; looks better than &#60;div class="header"&#62;. What do we really gain here by being more "semantic"? Aren't we just trading reliability for fashion?
评论 #2558853 未加载
toddmoreyabout 14 years ago
I don't think Modernizr causes harm if you <i>understand and act like</i> the resulting CSS styles are javascript dependent (as you should with any JS-based progressive enhancement). He's right, though: there are more conditions than you'd think where javascript may not be available. Make sure to ask yourself if the effect you want is possible without javascript first (as in the button example). And always test your pages for usability with javascript turned off.
oozcitakabout 14 years ago
There are only a handful of browsers that doesn't support javascript today [1]. There also users consciously disabling scripting on their modern browsers but they don't add up to a significant percent of browser users [2]. The second argument that an external .js file can fail to load applies to the .css file as well.<p>There may be arguments against the modernizr approach, but the ones in the article are quite weak.<p>[1]: <a href="http://en.wikipedia.org/wiki/Comparison_of_web_browsers#JavaScript_support" rel="nofollow">http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Java...</a><p>[2]: <a href="http://visualrevenue.com/blog/2007/08/eu-and-us-javascript-disabled-index.html" rel="nofollow">http://visualrevenue.com/blog/2007/08/eu-and-us-javascript-d...</a>
c4urselfabout 14 years ago
i can't advise modernizr as _the_ answer to html/css compatibility either, that being said it's a great tool to get started using html5 css3 until a) a better tool comes along or b) browser compatibility issues go away ...