Question

In: Computer Science

Choose one HTML5 API in the W3Cs HTML5 specification. In your own words, describe what this...

Choose one HTML5 API in the W3Cs HTML5 specification. In your own words, describe what this particular API does and give an example of how it can be used within a Web page. Please type out in text, as handwriting is often hard to read. Be as detailed as possible please. Thank you in advance!

Solutions

Expert Solution

The tools available to create powerful applications on the web platform are getting better with each passing year. The HTML5 specification has added a number of useful features in new APIs that you may not have delved into yet, likely because of the lack of browser support.

In this post, we’ll take a look at 10 HTML5 APIs that cover a whole slew of functionality and features that can help you create interactive websites, test the performance of your code, interact with a user’s device, and much more.

User Timing API:

The first step in speeding up a slow web application is working out where time is being spent. Measuring the time impact of areas of Javascript code is the ideal way to identify hot spots, which is the first step in finding how to improve performance. Fortunately the User Timing API provides a way that you can insert API calls at different parts of your Javascript and then extract detailed timing data that can be used to help you optimize.

API created for testing the performance of our code is the User Timing API. With the High Resolution Time API, we can retrieve the current time in sub-millisecond resolution but it leaves us with the pain of introducing a bunch of variables in our code. The User Timing API solves this and other problems.

It allows us to accurately measure and report the performance of a section of JavaScript code. It deals with two main concepts: mark and measure. The former represents an instant (timestamp), while the latter represents the time elapsed between two marks.

This API exposes four methods, all belonging to the window.performance object, that allow us to store and delete marks and measures. The mark(name) method is used to store a timestamp with an associated name, while measure(name[, mark1[, mark2]]) can be used to store the time elapsed between two marks with the provided name.

The desktop and mobile browsers that support the User Timing API are IE10+, Chrome 25+, and Opera 15+.

The User Timing interface allows the developer to create application specific timestamps that are part of the browser's performance timeline. There are two types of user defined timing event types: the "mark" event type and the "measure" event type.

mark events are named by the application and can be set at any location in an application. measure events are also named by the application but they are placed between two marks thus they are effectively a midpoint between two marks.

This document provides an overview of the mark and measure performance event types including the four User Timing methods that extend the Performance interface.

To get the current time in your web application, call the 'now()' method which forms an extension of the Performance interface. The following code shows how to do that:

var myTime = window.performance.now();

When trying to time web applications in the past you’d use something like Date.now() which returns a DOMTimeStamp. DOMTimeStamp returns an integer number of milliseconds as its value.

The User Timing interface provides functions that let us call methods at different places in our application that can provide a Hansel and Gretel style breadcrumb trail to let us track where the time is being spent.

The ‘mark()’ method is the main tool in our timing analysis toolkit. What mark() does is store a time stamp for us. What’s super useful about mark() is that we can name the time stamp, and the API will remember the name and the time stamp as a single unit.

Calling mark() at various places in your application lets you work out how much time it took you hit that ‘mark’ in your web application.

window.performance.mark('mark_fully_loaded');

The measure() method calculates the elapsed time between marks, and can also measure the time between your mark and any of the well-known event names in the PerformanceTiming interface.

Sometimes it’s useful to be able to get rid of a bunch of marks that you’ve set up. For example, you might do batch runs on your web application and so you want to start fresh each run.

It’s easy enough to get rid of any marks you’ve set up by calling 'clearMarks()'.

var items = window.performance.getEntriesByType('mark');

returns us a list of all the marks that have been hit in our web application, whilst the code:

var items = window.performance.getEntriesByType('measure');

returns us a list of all the measures we’ve made.

The User Timing API gives you a lot of great tools to apply to any aspect of your web application. Narrowing down the hot-spots in your application can be easily achieved by sprinkling API calls throughout your web application and post-processing the timing data generated to create a clear picture of where time is being spent. But what if your browser doesn’t support this API? No problem, you can find a great polyfill here that emulates the API really well and plays nicely with webpagetest.org as well. So what are you waiting for? Try out the User Timing API on your applications now, you’ll work out how to speed them up and your users will thank you for making their experience so much better.


Related Solutions

Anwser in your own words Describe in your own words, what should be included in health...
Anwser in your own words Describe in your own words, what should be included in health record documentation best practices. Provide at least one example of how HIM's ensure these best practices are met.
Choose one of the influences to the global consumer. Define the influence in your own words....
Choose one of the influences to the global consumer. Define the influence in your own words. Provide an example of the influence from the Internet, and discuss how the influence played out in that story. Put on your CEO hat - what would you do to try and take that influence into account with your product or service?
1. Describe in your own words the structure of DNA. 2. Describe in your own words...
1. Describe in your own words the structure of DNA. 2. Describe in your own words how DNA makes copies of itself. (I.e. Describe DNA replication.). Protein synthesis involves two processes, transcription and translation. Describe in your own words how each process occurs. Transcription Translation
write a short essay about The API 20E in your own words to understand its uses.
write a short essay about The API 20E in your own words to understand its uses.
In your own words, describe what is the Universal Declaration of Human Rights. In your own...
In your own words, describe what is the Universal Declaration of Human Rights. In your own words, list and describe at least three implications on health as a result of migration. please.don't copy and paste
Describe a religion that is not your own. Choose from one of the following religions: Ancient...
Describe a religion that is not your own. Choose from one of the following religions: Ancient Egyptian belief, Hinduism, Greek or Roman Polytheism, Native American Religion, Buddhism, Taoism, Judaism, Christianity, or Islam. You must choose a religion that is not your own. Describe three features or tenets of the chosen religion. Mention any written works and prophets. Share how this religion compares to your religion or beliefs, even if you do not have a chosen "religion."
Discuss in your own words the major characteristics of a Project. In your own words, describe...
Discuss in your own words the major characteristics of a Project. In your own words, describe the benefits of a structured Project approach.
Choose to either defend amazon or enforce antitrust. in one paragraph explain in your own words...
Choose to either defend amazon or enforce antitrust. in one paragraph explain in your own words your reason for choosing your side. Please support your decision with facts and at least 1 reference (website).
In your own words describe what your thoughts are on culture and mate selection
In your own words describe what your thoughts are on culture and mate selection
What are the five special senses? Briefly describe each sense in your own words. Select one...
What are the five special senses? Briefly describe each sense in your own words. Select one the five special senses. What is one example of an injury or disorder that would affect this special sense? In what way would the special sense be affected?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT