HTML5 Boilerplate homepage | Documentation table of contents
Here is some useful advice for how you can make your project with HTML5 Boilerplate even better. We don't want to include it all by default, as not everything fits with everyone's needs.
- App Stores
- DNS prefetching
- Google Universal Analytics
- Internet Explorer
- Miscellaneous
- News Feeds
- Search
- Social Networks
- URLs
- Web Apps
Users can install a Chrome app directly from your website, as long as the app and site have been associated via Google's Webmaster Tools. Read more on Chrome Web Store's Inline Installation docs.
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/APP_ID">
Stop bothering everyone with gross modals advertising your entry in the App Store. This bit of code will unintrusively allow the user the option to download your iOS app, or open it with some data about the user's current state on the website.
<meta name="apple-itunes-app" content="app-id=APP_ID,app-argument=SOME_TEXT">
In short, DNS Prefetching is a method of informing the browser of domain names referenced on a site so that the client can resolve the DNS for those hosts, cache them, and when it comes time to use them, have a faster turn around on the request.
There is a lot of prefetching done for you automatically by the browser. When the browser encounters an anchor in your html that does not share the same domain name as the current location the browser requests, from the client OS, the IP address for this new domain. The client first checks its cache and then, lacking a cached copy, makes a request from a DNS server. These requests happen in the background and are not meant to block the rendering of the page.
The goal of this is that when the foreign IP address is finally needed it will already be in the client cache and will not block the loading of the foreign content. Fewer requests result in faster page load times. The perception of this is increased on a mobile platform where DNS latency can be greater.
<meta http-equiv="x-dns-prefetch-control" content="off">
Even with X-DNS-Prefetch-Control meta tag (or http header) browsers will still prefetch any explicit dns-prefetch links.
WARNING: THIS MAY MAKE YOUR SITE SLOWER IF YOU RELY ON RESOURCES FROM FOREIGN DOMAINS.
Typically the browser only scans the HTML for foreign domains. If you have resources that are outside of your HTML (a javascript request to a remote server or a CDN that hosts content that may not be present on every page of your site, for example) then you can queue up a domain name to be prefetched.
<link rel="dns-prefetch" href="//example.com">
<link rel="dns-prefetch" href="//ajax.googleapis.com">
You can use as many of these as you need, but it's best if they are all
immediately after the Meta
Charset
element (which should go right at the top of the head
), so the browser can
act on them ASAP.
Amazon S3:
<link rel="dns-prefetch" href="//s3.amazonaws.com">
Google APIs:
<link rel="dns-prefetch" href="//ajax.googleapis.com">
Microsoft Ajax Content Delivery Network:
<link rel="dns-prefetch" href="//ajax.microsoft.com">
<link rel="dns-prefetch" href="//ajax.aspnetcdn.com">
Chrome, Firefox 3.5+, Safari 5+, Opera (Unknown), IE 9 (called "Pre-resolution" on blogs.msdn.com)
- https://developer.mozilla.org/en-US/docs/Controlling_DNS_prefetching
- http://dev.chromium.org/developers/design-documents/dns-prefetching
- http://www.apple.com/safari/whats-new.html
- http://blogs.msdn.com/b/ie/archive/2011/03/17/internet-explorer-9-network-performance-improvements.aspx
- http://dayofjs.com/videos/22158462/web-browsers_alex-russel
The optimized Google Universal Analytics snippet included with HTML5 Boilerplate includes something like this:
ga('create','UA-XXXXX-X'); ga('send','pageview');
To customize further, see Google's Advanced Setup, Pageview, and Event Docs.
In some countries, no personal data may be transferred outside jurisdictions
that do not have similarly strict laws (i.e. from Germany to outside the EU).
Thus a webmaster using the Google Univeral Analytics may have to ensure that
no personal (trackable) data is transferred to the US. You can do that with
the ga('set', 'anonymizeIp', true);
parameter
before sending any events/pagviews. In use it looks like this:
ga('create','UA-XXXXX-X');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
An article by @JangoSteve explains how to track jQuery AJAX requests in Google Analytics.
Add this to plugins.js
:
/*
* Log all jQuery AJAX requests to Google Analytics
* See: http://www.alfajango.com/blog/track-jquery-ajax-requests-in-google-analytics/
*/
if (typeof ga !== "undefined" && ga !== null) {
$(document).ajaxSend(function(event, xhr, settings){
ga('send', 'pageview', settings.url);
});
}
Add this function after ga
is defined:
(function(window){
var undefined,
link = function (href) {
var a = window.document.createElement('a');
a.href = href;
return a;
};
window.onerror = function (message, file, line, column) {
var host = link(file).hostname;
ga('send', {
'hitType': 'event',
'eventCategory': (host == window.location.hostname || host == undefined || host == '' ? '' : 'external ') + 'error',
'eventAction': message,
'eventLabel': (file + ' LINE: ' + line + (column ? ' COLUMN: ' + column : '')).trim(),
'nonInteraction': 1
});
};
}(window));
Add this function after ga
is defined:
$(function(){
var isDuplicateScrollEvent,
scrollTimeStart = new Date,
$window = $(window),
$document = $(document),
scrollPercent;
$window.scroll(function() {
scrollPercent = Math.round(100 * ($window.height() + $window.scrollTop())/$document.height());
if (scrollPercent > 90 && !isDuplicateScrollEvent) { //page scrolled to 90%
isDuplicateScrollEvent = 1;
ga('send', 'event', 'scroll',
'Window: ' + $window.height() + 'px; Document: ' + $document.height() + 'px; Time: ' + Math.round((new Date - scrollTimeStart )/1000,1) + 's'
);
}
});
});
IE10 does not support plugins, such as Flash, in Metro mode. If your site requires plugins, you can let users know that via the X-UA-Compatible meta element, which will prompt them to switch to Desktop Mode.
<meta http-equiv="X-UA-Compatible" content="requiresActiveX=true">
Here's what it looks like alongside H5BP's default X-UA-Compatible values:
<meta http-equiv="X-UA-Compatible" content="IE=edge,requiresActiveX=true">
You can find more information in Microsoft's IEBlog post about prompting for plugin use in IE10 Metro Mode.
Enabling your application for pinning will allow IE9 users to add it to their Windows Taskbar and Start Menu. This comes with a range of new tools that you can easily configure with the elements below. See more documentation on IE9 Pinned Sites.
Without this rule, Windows will use the page title as the name for your application.
<meta name="application-name" content="Sample Title">
You know — a tooltip. A little textbox that appears when the user holds their mouse over your Pinned Site's icon.
<meta name="msapplication-tooltip" content="A description of what this site does.">
If the site should go to a specific URL when it is pinned (such as the
homepage), enter it here. One idea is to send it to a special URL so you can
track the number of pinned users, like so:
http://www.example.com/index.html?pinned=true
<meta name="msapplication-starturl" content="http://www.example.com/index.html?pinned=true">
IE9+ will automatically use the overall color of your Pinned Site's favicon to
shade its browser buttons. UNLESS you give it another color here. Only use
named colors (red
) or hex colors (#ff0000
).
<meta name="msapplication-navbutton-color" content="#ff0000">
If the site should open at a certain window size once pinned, you can specify the dimensions here. It only supports static pixel dimensions. 800x600 minimum.
<meta name="msapplication-window" content="width=800;height=600">
Add Jump List Tasks that will appear when the Pinned Site's icon gets a right-click. Each Task goes to the specified URL, and gets its own mini icon (essentially a favicon, a 16x16 .ICO). You can add as many of these as you need.
<meta name="msapplication-task" content="name=Task 1;action-uri=http://host/Page1.html;icon-uri=http://host/icon1.ico">
<meta name="msapplication-task" content="name=Task 2;action-uri=http://microsoft.com/Page2.html;icon-uri=http://host/icon2.ico">
Windows 8 adds the ability for you to provide a PNG tile image and specify the tile's background color. Full details on the IE blog.
- Create a 144x144 image of your site icon, filling all of the canvas, and using a transparent background.
- Save this image as a 32-bit PNG and optimize it without reducing
colour-depth. It can be named whatever you want (e.g.
metro-tile.png
). - To reference the tile and its color, add the HTML
meta
elements described in the IE Blog post.
IE10 will poll an XML document for badge information to display on your app's tile in the Start screen. The user will be able to receive these badge updates even when your app isn't actively running. The badge's value can be a number, or one of a predefined list of glyphs.
<meta name="msapplication-badge" value="frequency=NUMBER_IN_MINUTES;polling-uri=http://www.example.com/path/to/file.xml">
Similar to -webkit-tap-highlight-color in iOS Safari. Unlike that CSS property, this is an HTML meta element, and its value is boolean rather than a color. It's all or nothing.
<meta name="msapplication-tap-highlight" content="no" />
You can read about this useful element and more techniques in Microsoft's documentation on adapting WebKit-oriented apps for IE10.
<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml">
According to Heather Champ, former community manager at Flickr, you should not allow search engines to index your "Contact Us" or "Complaints" page if you value your sanity. This is an HTML-centric way of achieving that.
<meta name="robots" content="noindex">
WARNING: DO NOT INCLUDE ON PAGES THAT SHOULD APPEAR IN SEARCH ENGINES.
Sites with in-site search functionality should be strongly considered for a browser search plugin. A "search plugin" is an XML file which defines how your plugin behaves in the browser. How to make a browser search plugin.
<link rel="search" title="" type="application/opensearchdescription+xml" href="">
-
Use HTML5 polyfills.
-
Use Microformats (via microdata) for optimum search results visibility.
-
If you're building a web app you may want native style momentum scrolling in iOS 5+ using
-webkit-overflow-scrolling: touch
. -
If you want to disable the translation prompt in Chrome or block Google Translate from translating your web page, use
<meta name="google" value="notranslate">
. To disable translation for a particular section of the web page, addclass="notranslate"
. -
Avoid development/stage websites "leaking" into SERPs (search engine results page) by implementing X-Robots-tag headers.
-
Screen readers currently have less-than-stellar support for HTML5 but the JS script accessifyhtml5.js can help increase accessibility by adding ARIA roles to HTML5 elements.
Have an RSS feed? Link to it here. Want to learn how to write an RSS feed from scratch?
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml">
Atom is similar to RSS, and you might prefer to use it instead of or in addition to it. See what Atom's all about.
<link rel="alternate" type="application/atom+xml" title="Atom" href="/atom.xml">
Your server may be notified when another site links to yours. The href attribute should contain the location of your pingback service.
<link rel="pingback" href="">
- High-level explanation: http://codex.wordpress.org/Introduction_to_Blogging#Pingbacks
- Step-by-step example case: http://www.hixie.ch/specs/pingback/pingback-1.0#TOC5
- PHP pingback service: http://blog.perplexedlabs.com/2009/07/15/xmlrpc-pingbacks-using-php/
You can control the information that Facebook and others display when users share your site. Below are just the most basic data points you might need. For specific content types (including "website"), see Facebook's built-in Open Graph content templates. Take full advantage of Facebook's support for complex data and activity by following the Open Graph tutorial.
<meta property="og:title" content="">
<meta property="og:description" content="">
<meta property="og:image" content="">
Twitter provides a snippet specification that serves a similar purpose to Open Graph. In fact, Twitter will use Open Graph when Cards is not available. Note that, as of this writing, Twitter requires that app developers activate Cards on a per-domain basis. You can read more about the various snippet formats and application process in the official Twitter Cards documentation.
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@site_account">
<meta name="twitter:creator" content="@individual_account">
<meta name="twitter:url" content="http://www.example.com/path/to/page.html">
<meta name="twitter:title" content="">
<meta name="twitter:description" content="">
<meta name="twitter:image" content="http://www.example.com/path/to/image.jpg">
Signal to search engines and others "Use this URL for this page!" Useful when
parameters after a #
or ?
is used to control the display state of a page.
http://www.example.com/cart.html?shopping-cart-open=true
can be indexed as
the cleaner, more accurate http://www.example.com/cart.html
.
<link rel="canonical" href="">
Signal to the world "This is the shortened URL to use this page!" Poorly supported at this time. Learn more by reading the article about shortlinks on the Microformats wiki.
<link rel="shortlink" href="h5bp.com">
If you use separate URLs for desktop and mobile users, you should consider helping search engine algorithms better understand the configuration on your web site.
This can be done by adding the following annotations in your HTML pages:
-
on the desktop page, add the
link rel="alternate"
tag pointing to the corresponding mobile URL, e.g.:<link rel="alternate" media="only screen and (max-width: 640px)" href="http://m.example.com/page.html" >
-
on the mobile page, add the
link rel="canonical"
tag pointing to the corresponding desktop URL, e.g.:<link rel="canonical" href="http://www.example.com/page.html">
For more information please see:
- https://developers.google.com/webmasters/smartphone-sites/details#separateurls
- https://developers.google.com/webmasters/smartphone-sites/feature-phones
There are a couple of meta tags that provide information about a web app when added to the Home Screen on iOS:
-
Adding
apple-mobile-web-app-capable
will make your web app chrome-less and provide the default iOS app view. You can control the color scheme of the default view by addingapple-mobile-web-app-status-bar-style
.
-
You can use
apple-mobile-web-app-title
to add a specific sites name for the Home Screen icon. This works since iOS 6.
On iOS 7.1, you can minimize the top and bottom bars on the iPhone as the page
loads, simply by adding the minimal-ui
property to the viewport
meta tag.
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
For further information please read the official documentation on Apple's site.
Touch Icons can be seen as the favicons of mobile devices and tablets.
If your site or icons are in a sub-directory, you will need to reference the
icons using link
elements placed in the HTML head
of your document, e.g.:
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png">
The main sizes of the icons on iOS are:
57×57px
– non-Retina iPhone and iPod Touch72×72px
– iPad mini and the first- and second-generation iPad on iOS ≤ 676×76px
– iPad mini and the first- and second-generation iPad on iOS ≥ 7114×114px
– iPhone 4+ (with Retina Display) on iOS ≤ 6120×120px
– iPhone 4+ (with Retina Display) on iOS ≥ 7144×144px
– iPad 3+ (with Retina Display)152×152px
– iPad 3+ (with Retina Display)
For non-Retina iPhone, iPod Touch, and Android 2.1+ devices you can use the
example from above or replace the apple-touch-icon-precomposed.png
within
this project's root folder.
In most cases, one 152×152px
touch icon named apple-touch-icon-precomposed.png
is enough. If you use art-direction and want to have different content for each
size, you can add more touch icons as written above.
As of iOS 7, no special effects are applied to the touch icons. So, if you are
only targeting iOS 7 and up, you don’t have to use precomposed
anymore (but
we strongly recommend you
do!).
For a more comprehensive overview, please refer to Mathias' article on Touch Icons.
Apart from that it is possible to add start-up screens for web apps on iOS. This
basically works by defining apple-touch-startup-image
with an according link
to the image. Since iOS devices have different screen resolutions it is
necessary to add media queries to detect which image to load. Here is an
example for a retina iPhone:
<link rel="apple-touch-startup-image" media="(max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)" href="img/startup-retina.png">
However, it is possible to detect which start-up image to use with JavaScript. The Mobile Boilerplate provides a useful function for this. Please see helpers.js for the implementation.
Chrome Mobile has a specific meta tag for making apps installable to the homescreen which tries to be a more generic replacement to Apple's proprietary meta tag:
<meta name="mobile-web-app-capable" content="yes">
Same applies to the touch icons:
<link rel="icon" sizes="196x196" href="highres-icon.png">
Many thanks to Brian Blakely for contributing much of this information.