Could FontLoader error and fileerror events trigger right away?
danzen opened this issue · 3 comments
It seems that if I have a broken font URL I see an error in the console right away but I am waiting the default 8 seconds for the error event to trigger. I might be wrong - but that seems to be what is happening. I could not get the fileerror event to trigger so this is using the error event. And I am just using a bad url to the font.
We don't load fonts as files. Instead we create CSS that triggers the font load in the browser, and then poll a canvas to determine when its loaded. Because of this, we do not receive the 404 error that the browser throws up.
There might be a way to do this by determining the font path, preloading it with XHR (as long as the domain supports CORS), and surfacing the 404 before doing the actual font preload -- but I am not sure how handy that would be, and it could load the font file twice (once in the browser cache and once for the XHR version).
Open to ideas....
What about a shorter timeout for fonts - so offer a fontTimeout (or whatever) parameter that defaults to 2 seconds as fonts would normally not take as long as images to load. Not sure if that is always the case but probably... Then if there are no traditional assets still loading and the fontTimeout has passed, trigger the error. I suppose we could separate out our font loads and set the default time to shorter, but we would not have to if CreateJS handled it.
Could be a reasonable solution.