Yuav ua li cas yog deferred scripts hauv JavaScript?
Yuav ua li cas yog deferred scripts hauv JavaScript?

Video: Yuav ua li cas yog deferred scripts hauv JavaScript?

Video: Yuav ua li cas yog deferred scripts hauv JavaScript?
Video: Kuv Tsis Paub Yuav Ua Li Cas - Tupao Xiong (Lyrics) 2024, Kaum ib hlis
Anonim

Cov ncua attribute qhia rau tus browser tias nws yuav tsum mus ua haujlwm nrog nplooj ntawv, thiab thauj khoom tsab ntawv "nyob rau hauv keeb kwm yav dhau", ces khiav lub tsab ntawv thaum nws loads. Cov ntawv nrog ncua yeej tsis thaiv nplooj ntawv. Cov ntawv nrog ncua ib txwm ua thaum DOM npaj txhij, tab sis ua ntej DOMContentLoaded tshwm sim.

Kuj kom paub yog, dab tsi yog ncua hauv JavaScript?

Kev cog lus yog qhov chaw rau qhov tshwm sim uas yog thawj zaug tsis paub thaum a ncua sawv cev rau kev xam uas ua rau tus nqi. Thaum cov lus cog tseg yog tus nqi xa rov qab los ntawm kev ua haujlwm asynchronous, a ncua tuaj yeem daws lossis tsis lees paub los ntawm nws tus neeg hu xov tooj uas cais cov lus cog tseg los ntawm tus neeg daws teeb meem.

Qhov thib ob, dab tsi yog async defer hauv JavaScript? Async vs Defer Nrog async , cov ntaub ntawv tau downloaded asynchronously thiab ces tua sai li sai tau thaum nws yog downloaded. Nrog ncua , cov ntaub ntawv tau rub tawm asynchronously, tab sis tsuas yog ua tiav thaum cov ntaub ntawv parsing tiav. Nrog ncua , scripts yuav ua tib yam li lawv hu.

Raws li txoj cai, qhov txawv ntawm asynchronously loading ib tsab ntawv thiab ncua kev thauj khoom ntawm cov ntawv sau?

Cov qhov sib txawv ntawm async thiab ncua centers nyob ib ncig ntawm thaum lub tsab ntawv raug tua. Txhua async tsab ntawv executes ntawm thawj lub sijhawm tom qab nws tiav rub tawm thiab ua ntej lub qhov rais thauj xwm txheej. Raws li qhov ncua scripts , ntawm qhov tod tes, tau lees tias yuav raug tua hauv xaj lawv tshwm sim hauv nplooj.

Yuav ua li cas ntxiv defer hauv JavaScript?

Cov DEFER Txoj Kev Koj ua tau ntxiv lub ncua ” tus cwj pwm rau txhua qhov ntawm koj lub cim npe sab nraud. Dab tsi yog ' ncua ' attribute puas yog qhia lub web browser kom tsis txhob thauj nws mus txog thaum HTML tau ua tiav kev thauj khoom.

Pom zoo: