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.

91 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
  • 13,193
  • 16
  • 65
  • 98
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,027
  • 3
  • 22
  • 43
3
votes
2 answers

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
  • 33
  • 1
  • 4
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 can I make jQuery replaceWith() "non-blocking" (async)?

I'm using the function replaceStr() to replace some strings in the body tag. If the html page is small, the replacing is not noticeable. But if the html page is bigger and more complex you notice it. The replacing is blocking the browser. My…
2
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
  • 8,944
  • 12
  • 43
  • 78
2
votes
2 answers

Render called before setState updates state

Is there any way to make sure render is called after setState actually updates the state? From my knowledge, setState is asynchronous. I have tried putting render as the callback to setState, but it still renders before the state is updated. HTML…
1
vote
2 answers

Why can't I access api fetch response?

I'm new to asynchronous processes and I don't understand why my current method of trying to store a response from a fetch request to an api is not working. I'm building and Angular app, where I have a api.service.ts file where I define my fetch…
1
vote
0 answers

Readline passed a callback on.close execution order

Here I'm using the Readline module inside a function that executes a callback function on.close. It executes in the expected order (the code on.close, then the code in the callback passed to it, this can be seen with the console.log statements),…
Mick
  • 171
  • 1
  • 8
1
vote
1 answer

Execute javascript async function and return result in selenium

I am trying to execute the following script in selenium result = driver.execute_script('let result; await axe.run().then((r)=> {result=r}); return result;') But it is returning javascript error: await is only valid in async function I also…
1
vote
1 answer

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
  • 35
  • 3
1
vote
1 answer

React Native - How to deal with asynchronism with AsyncStorage

I am facing to asynchronism problem : I create a user in firebase, generating a unique ID for it. I get this unique ID. I call an async function to persist this ID with AsyncStorage method. Problem : The asyncStorage method is called before I get…
1
vote
3 answers

Trouble fetching data with Async/Await

Hi I'm trying to fetch a country's data after which I want to fetch the names for its neighboring countries. import React from 'react'; export default function DetailsRoute({ match }) { const [countryData, setCountryData] =…
1
2 3 4 5 6 7