Search Unity

Bug No download progress indication on Chrome when using gzip

Discussion in 'Web' started by De-Panther, Apr 3, 2021.

  1. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    Unity 2020.2.6f1
    The "loader.js" file uses XMLHttpRequest to download the data file.
    This download request is also used to indicate the download progress.

    Chrome has this old WontFix bug https://bugs.chromium.org/p/chromium/issues/detail?id=463622

    That means that to indicate download progress of GZIP files on Chrome, we need to use Fetch.

    Didn't see any reference to a related issue in the Release Notes since Unity 2020.2.6f1, so I guess it's there on newer versions.

    I can manually edit the code and replace the XHR with Fetch (and using "body.getReader()"), but is there a "correct" way to edit the loader file?
    (I prefer to do it from the JS side, rather than creating a C# script that edits the loader file after build)

    Thanks
     
    Last edited: Apr 3, 2021
    KamilCSPS and gtk2k like this.
  2. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    I ended up creating a copy of Unity's "loader.js" in my template, and altering the "downloadBinary" function to use fetch instead of XMLHttpRequest.

    @jukka_j is there a plan to use fetch instead of XMLHttpRequest for downloads of the framework/data files?
     
    KamilCSPS and gtk2k like this.
  3. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    We have a PR that's in the final stages that replaces XMLHttpRequest with Fetch, for this very reason.
     
    KamilCSPS, siliwangi and De-Panther like this.
  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Like Brendan mentioned, this has been in the TODO queue for a while, and we have now just approved to land a change that removes the use of XHR, and replaces that with the Fetch API.

    That work also refactored how we handle IndexedDB persistence, and we are looking to improve these facilities for better debugging and development experience as well.

    The general UnityWebRequest API will also soon follow, so Unity won't use XHRs at all to do requests.
     
    KamilCSPS and De-Panther like this.
  5. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    Would there be a script that migrate from old IndexedDB handling to new?
    (delete old data, transfer old data to new?)
     
  6. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    The IndexedDB implementation should be compatible, i.e. the data scheme itself is unchanged. Just the implementation of the code that does the persisting is what changes.

    Though there will be new fields added in the future. The major thing we are looking to support is an improved control over persistence (expiration time, LRU eviction, evict after doing a new build)
     
    De-Panther likes this.
  7. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    Cool.

    Have to mentioned that I like the use of Macros and Conditional Directives in the new templates.
    All I had to do was to copy the original loader file from the editor folders as is, and only change the relevant part.
    All the macros and conditionals in the file worked.

    Only issue was that the original loader get compressed, but scripts in the template don't.
     
  8. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Oh do you mean when you embed custom .js files in your template, they won't get the .js.gz or .js.br compression?

    That is a good note, those files aren't minified either. I think we currently just copy them over.

    Maybe we should make a feature to also minify and compress them, although there will certainly need to be some options around that so that developers can configure it accordingly.
     
  9. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    Yes. But as long as the minify doesn't support ES6, it's ok that Unity doesn't try to minify and compress them by default.
    It's mostly nice to have
     
    Last edited: May 20, 2021
    jukka_j likes this.
  10. sampenguin

    sampenguin

    Joined:
    Feb 1, 2011
    Posts:
    64
    Did this update ever go live and in what version of Unity is it? I have a project in 2021.1.15f1 and it is definitely still using XHR.
    Or is there a place I can find an updated version of the .js script to replace older Unity versions templates with?
     
  11. KibsUnityStudios

    KibsUnityStudios

    Joined:
    Jun 27, 2023
    Posts:
    2
    Did this get implemented and release for UnityWebRequests?
     
  12. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    273
    The switch to using the Fetch API landed in 2021.2. Let me check on the UnityWebRequests question.
     
    KibsUnityStudios likes this.
  13. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    I'm using 2021.3.17 in one of the projects and it is there. UnityWebRequests are using Fetch.
    Don't know which version it landed.
     
    KibsUnityStudios likes this.
  14. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    273
    Yep, that's right. Just confirmed making UnityWebRequests use the Fetch API landed in 2021.2.19f1.
     
    De-Panther likes this.