fengari-web
fengari-web copied to clipboard
Browser console shows XHR warning due to fengari-web using synchronous requests (?)
Displayed warning:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help http://xhr.spec.whatwg.org/
This occurs right after loading fengari, no matter what I do in my actual program. I'm not sure if synchronous requests are needed. I'd expect all requests to be async as that is the default value, so the warning is a bit confusing.
Don't synchronous requests reduce responsiveness? Or doesn't that apply to how fengari works? (Not that performance is a major concern for me)
require will make synchronous requests so that it keeps the same semantic as in regular Lua.
To avoid that you can either remove the require and load that script with a <script> tag or use fengari-loader with webpack which will package your scripts into a single file.
In general, you need a way to get your module into package.preload or package.loaded so that require doesn't need to blocking-ly fetch it. fengari-web does this for you, but you can do it yourself if you want.
I see, thanks! The only require I'm using is
js = require "js"
as written in the README for fengari-interop. Can I access the JS API in another way without using require? I'm already loading fengari-web via <script> tag in the loader (html webpage), but I need to access those functions inside of the Lua scripts that make up the actual app :)
If you're using fengari-web, fengari-interop should already be loaded for you.
I have to admit, I totally forgot to check back. After looking into it again, it appears that dofile exhibits the same behaviour. I use a lot of calls to dofile to load modules dynamically.
For what it's worth, I couldn't care less if the loading is blocking in the context of my app (which isn't a website). However, if mainstream browsers eventually remove support for this, I would have to fix it in a rush, so I'd rather get rid of the warning now and be done with it.
Is there any way around it that will still allow me to access the Lua tables loaded in the typical fashion, ideally without adding unneeded complexity? I'd rather not load everything in JS and have to deal with more interoperability issues than absolutely necessary.