I try to optimize my pages by putting some async
attributes on my scripts. It seems to break my javascript since $(document).ready
is executed before the all scripts are loaded!
I saw that I can resolve my problem by putting $(window).load
instead of $(document).ready
but I was wondering if there is a better solution.
This solution trigger 2 problems in my case :
- I have to change all
$(document).ready
and tell all the developpers to not use it anymore
- The scripts will be executed after all images are loaded. My website has a lot of heavy images and I really need some scripts to be executed ASAP after dom is ready.
Do you have some magic tricks? Maybe putting all scripts at the end? use defer
instead of async
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…