performance.now-polyfill.js 854 B

123456789101112131415161718192021222324252627282930
  1. // relies on Date.now() which has been supported everywhere modern for years.
  2. // as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values
  3. // if you want values similar to what you'd get with real perf.now, place this towards the head of the page
  4. // but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed
  5. (function(){
  6. // prepare base perf object
  7. if (typeof window.performance === 'undefined') {
  8. window.performance = {};
  9. }
  10. if (!window.performance.now){
  11. var nowOffset = Date.now();
  12. if (performance.timing && performance.timing.navigationStart){
  13. nowOffset = performance.timing.navigationStart
  14. }
  15. window.performance.now = function now(){
  16. return Date.now() - nowOffset;
  17. }
  18. }
  19. })();