Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I was using async: false in ajax. I want to have the equivalent of this command in fetch. Apparently using async helps. But when I use the word async in the webpack, it does not work. i use webbpack 3.8.1 and in webpack.config.js:

 const path = require('path');
const webpack = require('webpack');
  
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractCSS = new ExtractTextPlugin('allstyles_for_store_details_naghashi.css'/*'allstyles_for_store_details.css'*//*'allstyles.css'*/);
 
module.exports = { 
    entry: {
         'main': './wwwroot/source/app_for_store_details_naghashi.js' ,
     },
       
    output: {
        path: path.resolve(__dirname, 'wwwroot/dist'),
        filename: 'bundle_for_store_details_naghashi.js' ,
        publicPath: 'dist/', 
    },
    plugins: [
        extractCSS,
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            Popper: ['popper.js', 'default']
        }),
        new webpack.optimize.UglifyJsPlugin(), 
    ],
    module: {
        rules: [
            {
                test: /\.css$/, use: extractCSS.extract(['css-loader?minimize'])
            }, 
            {
                test: /\.js?$/,
                use: {
                    loader: 'babel-loader', options: {
                        presets:
                            ['@babel/preset-react', '@babel/preset-env']
                    }
                }
            },           
        ]
    } 
}; 


in my file :
async function f12() {
    alert('13579-1122');  
}
f12(); 


It does not work when I use the word async.

What I have tried:

I searched the internet a lot but could not find an answer that would work on my project.
I want the program to wait for the fetch command to complete when the fetch command is running. I was using async: false in ajax. Please help me how to do this in fetch
Posted
Updated 13-Feb-22 0:55am
v2
Comments
Richard Deeming 14-Feb-22 10:16am    
Rather than trying to force your users' browsers to freeze their UI waiting for a web request synchronously, upgrade your WebPack to a version that supports async / await.

Either that, or rewrite your code to use continuation-passing: fetch(...).then(function(response) { ... })

Synchronous AJAX requests cause serious performance problems:
Why You Should Use XMLHttpRequest Asynchronously | x443[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900