Skip to content

Pre load scripts so they are cached#10363

Merged
charleyf merged 2 commits intomainfrom
charley/cache-passive-liveness-scripts
Apr 22, 2024
Merged

Pre load scripts so they are cached#10363
charleyf merged 2 commits intomainfrom
charley/cache-passive-liveness-scripts

Conversation

@charleyf
Copy link
Contributor

@charleyf charleyf commented Apr 4, 2024

🛠 Summary of changes

This PR loads four additional scripts from Acuant when the document-capture page loads. This makes it so that when the user clicks on the selfie capture, that screen opens much faster b/c the scripts are cached.

📜 Testing Plan

  • Run this branch locally, open the network tab for debugging,.
  • Make sure you turn off the "Disable cache" option in the network tab. We want caching enabled.
  • Load the document capture page. Note that the four new scripts load when you load the page. Also note how long it takes each one to load (something less than ~200ms each is expected).
  • Now click the selfie box, note that the four scripts are loaded again, but they are MUCH faster, something like ~30ms.

@charleyf charleyf marked this pull request as ready for review April 11, 2024 15:47
@dawei-nava
Copy link
Contributor

dawei-nava commented Apr 22, 2024

Well the number I got is around 200+ms for the json on mobile device. Functionally it still works.

ok, that may include wait time. So the download time seems similar. Guess that's what you are describing.

Copy link
Contributor

@dawei-nava dawei-nava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these only loaded when applicable for selfie, i.e. not when document capture only? I wasn't able to find where these script sources are assigned.

passiveLivenessSrc: getSelfieCaptureEnabled()
? acuantVersion && `/acuant/${acuantVersion}/AcuantPassiveLiveness.min.js`
: undefined,
faceLandmarkWeightsSrc: getSelfieCaptureEnabled()
Copy link
Contributor Author

@charleyf charleyf Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduth This is where the condition for the script loading is. Two points:

  • These scripts are loaded only when the selfie is required.
  • These scripts aren't actually -used- anywhere in our code. The point here is to cache them when we load the other Acuant scripts so when a user opens the selfie capture, there's a much smaller delay.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha 👍 The main thing for me was only doing the background load when selfie was enabled, which looks like this code is handing. Not sure why I wasn't seeing this code when I searched "weights" earlier! Probably user error 😄

@charleyf charleyf merged commit 27b14e2 into main Apr 22, 2024
@charleyf charleyf deleted the charley/cache-passive-liveness-scripts branch April 22, 2024 18:54
charleyf added a commit that referenced this pull request Apr 23, 2024
charleyf added a commit that referenced this pull request Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants