Guest User

Untitled

a guest
Jun 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  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.  
  4. // if you want values similar to what you'd get with real perf.now, place this towards the head of the page
  5. // but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed
  6.  
  7. (function(){
  8. // prepare base perf object
  9. if (typeof window.performance === 'undefined') {
  10. window.performance = {};
  11. }
  12.  
  13. if (!window.performance.now){
  14. const nowOffset = Date.now();
  15.  
  16. if (performance.timing && performance.timing.navigationStart){
  17. nowOffset = performance.timing.navigationStart
  18. }
  19.  
  20. window.performance.now = function now(){
  21. return Date.now() - nowOffset;
  22. }
  23. }
  24. })();
Add Comment
Please, Sign In to add comment