-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make use of user timing api if available #998
Conversation
const genKey = () => String(Date.now()) | ||
// use User Timing api (if present) for more accurate key precision | ||
let Time | ||
if (typeof window !== 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should import this from util/dom
import { isInBrowser } from '../util/dom'
We can also make it a const
const Time = isInBrowser ? (window.performance || Date) : Date
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@posva rebased with these changes :)
The result in the key is a bit different though. But it doesn't change anything. |
@posva Behavior will likely differ as
AFAIK there is no way for me to link a reference due to the nature of the tool, so here's a screenshot of the offending rule: For a closer look, download the official chrome extension and run it on any site that uses |
Screenshot is absolutely fine 👍 Thanks for sharing. Didn't know Lighthouse was checking that. Looks like a bit too much 😆 |
@posva I agree with you 100% - It's as if they've assumed |
@fnlctrl @yyx990803 maybe you see an edge case I'm missing |
@declandewet Unfortunately this doesn't remove the Lighthouse false positive edit: ofc its still there, there's a Date.now from somewhere else. |
@posva - this removes the false positive on my end, must be one of your other dependencies :) |
@declandewet Yes, I was testing with https://github.com/vuejs/vue-hackernews-2.0 |
@posva yeah - unfortunately there are valid use cases for The main benefit to focus on here is the one for accuracy - not the lighthouse audit :) since the That being said, now that I think about it - it might be worthwhile to profile the performance of this. I see virtually no difference except the few millisecond overhead of checking for |
(random rant) |
Actually, accuracy isn't a concern here - Date.now() is only being used as unique keys. As long as |
@fnlctrl "Progressive Web App" is just a term used to describe a website that behaves like a mobile app using a combination of these technologies. When following these best practices, if a user visits your "progressive web app" a second time 5 minutes after their first visit, Chrome on Android will prompt them to install the website to the home screen and have it behave just like any other app on their phone. This removes the need for the user to 1. see the app advertised somewhere 2. search for the app in the play store and 3. download the app - it increases conversions for the site quite marginally. Obviously, there's a very real threat that PWAs might kill app stores - and the Apple App Store is too much of a cash cow for them to allow that to happen, unfortunately :( (I'm sure there are many other reasons too)
|
Well, for vue-router, Date.now() won't produce duplicates as long as the user doesn't trigger pushState(which triggers genKey) more than once in a ms. If that's what the user wants I think we can just let it happen... I'm all for web apps killing native apps, but let's be realistic: unless the whole planet is dominated by Chrome and everyone stopped using iPhones (which uses Safari), it's just a waste of time trying to catch up with all these fancy new APIs that Chrome wants you to use. A prompt to install the website to the home screen? Sweet, but on Android only. Meh. It's a good thing PWA sets up a standard for people to improve their website performance, but I don't appreciate it selling these immature APIs. |
This introduces a client-side check for availability of the User Timing API and augments the
genKey
function to useperformance.now
instead ofDate.now
if the User Timing API is available.The benefits of this change are:
_key
is more precise in modern browsers (more specifically, instead of being a value that represents milliseconds since the unix epoch, it represents microseconds since the user started navigating - because microseconds are a smaller unit of measurement than milliseconds, this might generate more_key
s)vue-router
a better score for being a progressive web app)