Questions tagged [asynchronous-javascript]

Asynchronous JavaScript is a technique to load JavaScript asynchronously using async and defer attributes or script tag injection. Not to be confused with AJAX.

164 questions
18
votes
5 answers

Two different ways of putting the script at the bottom - what are the differences?

What are the differences between the two solutions below ? In particular, is there a good reason to favour 2 over 1. (note: Please assume the name of the script to load is known. The question is just about if there is value in creating a minimal…
Zo72
  • 14,593
  • 17
  • 71
  • 103
14
votes
1 answer

Why use `URL.createObjectURL(blob)` instead of `image.src`?

Q1. In the context of asynchronous JavaScript and the need to ‘fetch’ data from the client-side, why can’t we just edit our image elements by its attribute src? Q2. Why is the Blob conversion process necessary to go through? Q3. What is the blob…
hyfyline
  • 143
  • 1
  • 1
  • 5
4
votes
2 answers

Does the JS engine create a new microtask that will execute every handler chained together in a Promise object when resolve is invoked?

I recently encountered this question on Stack Overflow, asking about how the then method really works in JavaScript. The responder, Trincot, made the following comment: The host will check which job queues have entries, giving precedence to job…
4
votes
1 answer

Chrome.runtime.onMessage returns "undefined" even when value is known for asynchronous response

In my code I have a content script which requests a cookie from the background script. Even though I can print the cookie to the Dev Tool console, the message received from background script is always undefined. Why? Background script: // listens…
4
votes
0 answers

Redux saga: how to put a `yield put()` inside an event listener?

I'm using Redux saga and OneSignal in my React Native app. In my saga I have the following generator function: function* getOneSignalIDs() { try { OneSignal.init(appID) OneSignal.addEventListener('ids', (device) => { …
4
votes
1 answer

Nodejs + Mongodb: find data after aggregation

I'm a new to Nodejs and MongoDB. Here is a sample of my dataset: { 'name': ABC, 'age':24, 'gender':male, ... } Generally speaking, what I want to do is to aggregate data before using them to find different data clusters. To be specific, I…
4
votes
1 answer

Asynchronous java script loading is showing error

Asynchronous java script loading is showing the following error: Attribute name "async" associated with an element type "script" must be followed by the ' = ' character. + jsf I found this in my JSF2.4 application which uses template file…
Valsaraj Viswanathan
  • 1,473
  • 5
  • 28
  • 51
3
votes
2 answers

Async function passed as prop into React component causing @typescript-eslint/no-misused-promises error

I have the following asynchronous submitNewPatient function which is throwing @typescript-eslint/no-misused-promises error message from elint. Is it possible to adjust the function such that it removes this error? const submitNewPatient = async…
3
votes
4 answers

React hooks: how to detect when particular state variable has updated

Before React hooks, I would use componentDidUpdate(prevProps, prevState), and if I wanted to execute given code only when this.state.a had updated, I'd do if (prevState.a !== this.state.a) { <...> } How can I achieve the same thing in…
3
votes
2 answers

How to wait my custom command finish, then executing remaining Cypress commands

I'm getting trouble with Cypress asynchronous mechanism. I have a custom command that is placed in this file class HeaderPage { shopLink = 'a[href="/angularpractice/shop"]' homeLink = '' navigateToShopPage() { …
Hoang
  • 87
  • 1
  • 6
3
votes
1 answer

AWS SDK wait for asynchronous call to complete?

The AWS SDK documentation is not very clear about when/how/if asynchronous service calls can be made synchronous. For example, this page (https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/calling-services-asynchronously.html)…
aaa90210
  • 11,295
  • 13
  • 51
  • 88
3
votes
4 answers

Passing a named function in Javascript

How do you pass a named function with parameters without calling it. Right now the only solution I have seems like a hack but it is to pass an unnamed function that will call the named function. callback(function(){foo(params);}) Is there a better…
3
votes
5 answers

Defer loading of JavaScript - Uncaught ReferenceError: $ is not defined

I use google code to defer loading javascript (google pages) But I have some inline javascripts such as: And this gives me: Uncaught ReferenceError: $ is not…
2
votes
1 answer

How do I destructure an array wrapped in the Promise keyword in javascript?

I am trying to retrieve data from a PSQL table. And this is my code for that: async function requestData() { var selectQuery = `SELECT "fName", "lName", "phoneNumber", "eMail" FROM public."User"`; const {rows} = await…
2
votes
0 answers

executeScript() and executeAsyncScript() of javascriptExecutor interface is not behaving as expected

I know that executeScript() function of JavascriptExecutor interface in selenium requires no signalling mechanism and it executes javascript inside it as synchronous(single threaded). While executeAsyncScript() function of JavascriptExecutor…
1
2 3
10 11