What is different between HTML5 Polyfill and Fallback? - html

In http://html5please.com the each features listed by saying use with Polyfill or Fallback. I was wondering what is the different both? kindly help me in understanding the different.
Thanks in advance.

Polyfill replaces the feature with the same functionality but implemented with supported technologies, so you're still able to use the same API as in new browsers. For example, classList only supported starting from IE10, but you can add a script written in js that adds a classList object to any dom element so you don't need to rewrite your code to detect a browser or a feature.
Fallback usually replaces the feature with simplified functionality or third-party plugin or even error message. For example, if the browser does not support video tag, you can replace it with a flash plugin.
UPD: You can also check this question for more information.

Use with Polyfill means that there is some JavaScript code available to do more or less the same thing as the native browser feature.
Use with Fallback means that it isn't practical to emulate the feature using JavaScript, and you should provide some fallback so that the page still works on less capable browsers, albeit with reduced functionality.

Polyfill: A polyfill in web development is code that implements a feature on web browsers that do not support the feature. It usually refers to a JavaScript library that implements an HTML5 or CSS web standard, either an established standard (supported by some older browsers) or a proposed standard (not supported by any browsers) on existing browsers. "A polyfill is a shim for a browser API," according to the definition.
Fallback: The function is usually replaced with generalised functionality, a third-party plugin, or even an error message as a fallback.

Related

HTML 5 Substitute to javascript validation

I would like to know if HTML5 validation could already by used as a substitute to javascript validation.
HTML validation is so much easier and I want to implement it in my website but I am not sure of it is safe enough.
HTML5 validation is a feature that is fully implemented in several browsers, but is not fully implemented in many older browser versions, notably IE <10, Safari (all versions), as well as older versions of Chrome, Firefox, and Opera.
For those browsers that do not support it, however, you should look into using a Javascript polyfill such as Modernizr to ensure that users with other browsers will have their inputs validated as well. (There may be other polyfills available, but Modernizr is the most popular and widespread option currently available)
Check out this resource for HTML5 validations (see the required attribute). It goes on to explain browser compatibility:
http://diveintohtml5.info/forms.html

What happens if a browser that doesn't support HTML 5 encounters an HTML 5 website?

If you visit a site that uses Flash, and you don't have Flash installed on your browser, a message will be shown to you to install Flash. A similar procedure happens when Silverlight is involved instead of Flash.
What happens if a browser does not support HTML 5? Will I have to install something to get HTML 5 support in that case? Is that even possible?
Browsers will ignore elements it doesn't support and it won't apply css styles to those elements either. You won't get any explicit message that the browser doesn't support HTML5. You can, as the page author, provide your own message if the browser doesn't depending on the circumstance. You can, for example, provide a message that will display to the user inside a video or audio tag.
Well what happened earlier, wenn browsers supported HTML3 and you used HTML4? Nothing really, and that's what's going to happen for HTML5.
Flash and Silverlight are handled using browser plugins, so the browser can warn you if the plugin is not installed. HTML5 is not a plugin, so what you could do is to use JavaScript and check for the browser version.
Users won't get a message if their browser doesn't support certain html5.
What you could do is check what html5 or css3 you need, and look at http://caniuse.com/ wich browsers are compatible with those functions and then use a script to give older browser users a notification to update to a newer browser.
but what happen if a browser does not support HTML 5 ?
Exactly the same as what you described:
If you see when a site uses flash technology ,and you have not flash
component installed on you browser, a message will be shown to you to
install flash(same as silverlight)
This feature detection has absolutely nothing to do with HTML5. It's the implementation of the <object> tag that allows you to specify an url to download the component from if the browser hasn't installed it. It is a browser dependent implementation though.
#Ali Foroughi I didn't notice a clear cut work around if you have HTML 5 elements in a website and how to get older browsers namely IE 8 and older to display the new HTML5 elements. Other answers are true that the HTML5 element won't display correctly or at all but what can be done about this.
There a couple things you can do to either "teach" older browsers to handle HTML5 correctly either by CSS, JavaScript, or an HTML5Shiv. These methods are explained here.
Of course these can't be implemented by the end user but by the websites designer/developer.
Was searching for the answer as to a work around in case someone has an older browser and HTML5 elements are used. I figured if there are work around's for certain CSS styling by using some sort of webkit in the CSS file surely there is for HTML5.

Which HTML5 forms javascript polyfill to has the broadest feature and browser reach?

The new forms attributes and tags in HTML5 are great. Unfortunately, there is only limited support for these in Chrome and Firefox, and essentially no support of these in IE9 and below.
I have investigated using Modernizr and HTML5 polyfills to polyfill this functionality in browsers lacking native support. However, there seems to be a large number of polyfills for HTML5 forms functionality, such as webshims lib, webforms2 and h5f (see for example the listing at https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills) and I am not sure which one or ones I should invest the time in learning.
Which one of these HTML5 forms polyfills would give me the broadest coverage in terms of HTML5 features and browser coverage?
I have used Webshims Lib and like it because:
It runs 'more lightweight' if a browser supports more HTML5 form features natively (which, of course, should do any good polyfill).
You can simply use the declarative markup (attributes) of HTML5 forms in all cases.
The project seems to be more 'alive' than others.
By the way, the Webshims creator answered another question on stackoverflow quite convincingly: html5 forms with polyfills - is it worth it?

How to detect HTML 5 compatibility in browser

What is the best way to detect browser compatibility for HTML 5 syntax? And prompt the user if the browser is not compatible?
I understand the tutorial which shows how to test browser compatibility for HTML5. But I am curious to know if that is the only way? Do I need to inspect each and every element?
Have a look at Modernizr:
Taking advantage of the new capabilities of HTML5 and CSS3 can mean
sacrificing control over the experience in older browsers. Modernizr 2
is your starting point for making the best websites and applications
that work exactly right no matter what browser or device your visitors
use.
Thanks to the new Media Query tests and built-in YepNope.js
micro-library as Modernizr.load(), you can now combine feature
detection with media queries and conditional resource loading. That
gives you the power and flexibility to optimize for every
circumstance.
It has a lot of built in methods to test for browser features and provides a useful way of providing fallback code for when features you want to use are not supported.
More info: http://www.modernizr.com/
"HTML5 compatibility" is a very vague thing.
When people ask about HTML5 compatibility, they generally mean "what browsers support these new-ish browser features X, Y and Z which I want to use?"
There are a whole raft of features which have been added to browsers in the last couple of years, and which are now commonly referred to as "HTML5".
In fact, there aren't any browsers which support every new feature out there.
What you need to do is work out which features have wide enough support to make them worth using, which features you'd like to use but are happy to work around if you encounter a browser that doesn't support them, and which features you absolutely have to use to achieve what you want to do.
A fairly comprehensive list of new browser features, along with browser support charts for them all is available at http://caniuse.com/ (if you scroll to the bottom, you'll see in the overall compatibility table that the very best current browsers only support 89% of features they've tested. This will improve over time as new versions are released... but of course, also new features will be introduced too)
For determining at run-time whether the user's browser supports a given feature, you can use Modernizr. This is a Javascript-based tool which will give you a set of CSS classes and Javascript flags which tell you what features are supported. You can use this to trigger alternate behaviour in your site if the browser doesn't support a feature you want. (Modernizr also includes the HTML5Shim functionality, which allows IE to at least cope with HTML pages containing new HTML5 elements).
For more cross-browser compatibility, there are a whole range of hacks which have been written to allow older browsers (mainly IE to be fair) to support a range of newer features. You can see a fairly comprehensive list of them here: https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills
Obviously, trying to run more than a few of these at once in IE will severely impare your site's performance, but it can be handy if you need to support one or two features. My favourite at the moment is CSS3Pie, which gives IE6/7/8 support for CSS rounded corners, shadows and gradients.
Hope that helps.
Here is a tutorial of detecting HTML5 compatibility & capabilities :
http://diveintohtml5.ep.io/detect.html
There are alternative HTML5 detectors using similar techniques, but I would suggest to use Modernizr.
To sum up the "score" of HTML5, you can design your own "marking scheme". Sum up weighted score gives you the total score.
The simplest method : in JS you create a new element, and set the attributes to be a colorpicker (HTML5) in JS, and return the type of the element (it is a picker only if the browser ic HTML5 compatible) :
var element = document.createElement("input");
element.setAttribute("type", "color");
return element.type !== "text";
do I need to inspect each and every element?
Nope. Only the parts you want to use that aren’t backwards-compatible.
See Five Things You Should Know About HTML5, especially points 1 and 4.
I would suggest you can try using <audio>Anything within Audio tag here</audio>.
Any text written inside the between <audio> and </audio> will be displayed in browsers that do not support the <audio> tag.
Since the audio tag is newly added in HTML5.
This works on IE 11 (and hopefully other browsers too).
// Detect HTML v5 compatibility
var isHtml5Compatible = document.createElement('canvas').getContext != undefined;
It's a take from Clement's answer and the link from Shivan (http://diveintohtml5.info/detect.html). Clement's answer didn't work in IE 11.
In my case I use jQuery UI for everything so don't need Modernizr (also it seemed slower). Reading the rather negative "How to use Modernizr" blog comments supports this assumption.
But now jQuery have split browser compatibility between v1 and v2 development streams, its necessary for people wanting to support non-HTML v5 browsers to load EITHER the v1 or v2 jQuery core script at the start. So this "one liner" HTML v5 detection is perfect. Here's how I load jQuery properly using the result:
// Use jQuery v2 for HTML v5 browsers else v1 to support old browsers
var jQueryScriptPath = (isHtml5Compatible)
? "/Scripts/jquery-2.0.3.js"
: "/Scripts/jquery-1.10.2.js";
document.writeln("<script src=\"" + jQueryScriptPath + "\" type=\"text/javascript\"><\/script>");
If you vote this answer up please also vote clement and Shivan's answers too :-)

What can be used of HTML5 today?

What are the features of HTML5 that can be reliably used today?
Microsoft has some cool HTML5 demos, but what part of it is classic EEE and what is them catching up?
Example of useful feature I found on SO: pushState.
Please give more thought than a page with comprehensive lists of tags and attributes of HTML5.
#Jan Zyka's http://slides.html5rocks.com answer is a great example. (Thank you!)
What are you actually using in production code today?
There is a site called When can I use... which lists a variety of HTML5, CSS3, and other modern web standards, and gives an indication of which browser versions support it.
Whether or not you can use a feature depends a lot on who your users are. If you're targeting cutting-edge web developers, then you can likely rely on them having much later versions of browsers than if you're targeting corporate accounting. So, you will need to decide which browser versions you must support, and do appropriate progressive enhancement or fallback to support older browsers while introducing newer features that they don't support.
Some HTML5, CSS3, and other features can be used in older browsers using "polyfills," which are implementations of missing features using JavaScript, Flash, proprietary features, and the like. For instance, you can use <canvas> elements in older versions of Internet Explorer by using ExplorerCanvas, which implements the HTML5 <canvas> element using JavaScript and Microsoft's proprietary VML. The "When can I use..." site lists polyfills for many features, so check the polyfills checkbox if you're willing to use polyfills.
http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(HTML5)
http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(HTML5_Canvas)
http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(HTML5_Media)
http://caniuse.com/
https://developer.mozilla.org/en/HTML/HTML5 (what is implemented in Firefox)
List of HTML5 features that are implemented in IE8:
<meta charset="UTF-8">
the contenteditable attribute (making any HTML element editable)
the autocomplete attribute on form elements
the onhashchange event
drag and drop
data-* attributes
List of HTML5 features that are implemented in IE9 (additionally):
<canvas>
getElementsByClassName
<video> and <audio>
the new semantic elements(<section>, <article>, etc.)
inline SVG
Note: all of the above are implemented in the modern browsers.
Check out http://slides.html5rocks.com/. It's really nice and updated regularly.
But don't try it in IE8 otherwise you might be disappointed ;-)
This page on the Browserscope website lets you choose versions of the same or different browsers (both desktop & mobile) & see how they stack up in supporting HTML5 features.