Isivinini Sesiza ne-Javascript eyi-Asynchronous

njenge-asynchronous

Ngenkathi ngenza intuthuko enkulu, angizihlukanisi njengomqambi weqiniso. Ngiyakwazi ukuhlela nokuhambisa izinto ekhasini futhi ngikwenze kusebenze. Umthuthukisi weqiniso uyaqonda ukuthi angayithuthukisa kanjani ikhodi ukuze ikalwe, ingathathi izinsiza eziningi, ilayishe ngokushesha, iguqulwe kalula ngokuhamba kwesikhathi bese isebenza.

Indawo enzima abathengisi abafakwa kuyo bobabili bane- iwebhusayithi eshesha kakhulu futhi ngisafaka ukuhlanganiswa nezinto zomphakathi ezingadala ukuncika ekutheni isayithi lakho lizolayisha ngokushesha kangakanani. Esinye sezibonelo ezinjalo izinkinobho zenhlalo. KwaMartech, sinezinkinobho zokuxhumana nabantu ekhasini ngalinye elilodwa kusayithi. Ngakho-ke… uma izinsiza ze-Facebook zilayisha kancane ngelinye ilanga, kubambezela isiza sethu. Ngemuva kwalokho engeza i-Twitter, i-Pinterest, i-Buffer, njll kulokho namathuba esayithi lakho wokulayisha ngokushesha ancishiswa angabi yilutho.

Lokho kwaziwa njengokulayisha okuvumelanayo. Kufanele uqede ukulayisha into eyodwa ngaphambi ulayisha into elandelayo. Uma okwazi ukulayisha izinto ngokuvumelanayo, uyakwazi ukulayisha izinto ngaphandle kokuncika komunye nomunye. Ungasithuthukisa kakhulu isivinini sesayithi lakho ngokulayisha izinto ngokuzithandela. Inkinga ukuthi imibhalo engaphandle kwebhokisi oyinikezwa yilezi zinkampani cishe ayikaze yenzelwe ukusebenzisa i-asynchronous.
njenge-asynchronous

Ungabona ukuthi yini okuthinta isivinini sekhasi lakho ngokwenza isivivinyo ku-Pingdom:
umthwalo wephepha le-pingdom

I-Javascript eyi-Asynchronous ikuvumela ukuthi ubhale ikhodi etshela izinto ukuthi zilayishwe ngemuva ikhasi lilayishwe ngokuphelele. Akukho ukuncika! Ngakho-ke, ikhasi lakho ligcwele futhi uma seliqedile, umbhalo uqala ukuthi ulayisha ezinye izinto - kulokhu izinkinobho zethu zenhlalo. Uma ungunjiniyela, ungafunda i-athikili enhle, Ukulayisha okuvilaphayo iJavascript.

Nayi amazwibela okuthi ungakwenza kanjani kahle kusuka ku-Emil Stenström:

(function () {function async_load () {var s = document.createElement ('script'); s.type = 'text / javascript'; s.async = true; s.src = 'http://buttondomain.com /script.js '; var x = document.getElementsByTagName (' script ') [0]; x.parentNode.insertBefore (s, x);} uma (window.attachEvent) window.attachEvent (' onload ', async_load); enye iwindi.addEventListener ('load', async_load, false);}) ();

Umphumela uba ukuthi lokhu kuhlanganiswa komuntu wesithathu kuphansi noma kuhamba kancane, akukaze kube nomthelela kokuqukethwe kwekhasi lakho eliyinhloko ukuthi kungaveli. Uma ubheka umthombo wekhasi lethu, uzobona ukuthi ngilayisha yonke imibhalo eyengeziwe yomphakathi ngisebenzisa le ndlela. Inqubo ithuthukise imizuzwana yejubane lesayithi lethu - futhi ayiminyanisi ngesikhathi sokulayisha. Asikaguquki konke ukuncika kwethu kwangaphandle kwaba yi- I-Javascript eyi-Asynchronous, kodwa sizokwenza.

UCABANGANI?

Le sayithi isebenzisa i-Akismet ukunciphisa ugaxekile. Funda ukuthi idatha yakho yokuphawula isetshenziswa kanjani.