Optimise your code: load code at the right time

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ต.ค. 2024

ความคิดเห็น • 110

  • @faahim01
    @faahim01 5 ปีที่แล้ว +66

    This is nice!!!
    I'd love to see more content of this type! A bit more advanced topic won't hurt either! :D

    • @benmorss5609
      @benmorss5609 5 ปีที่แล้ว +1

      This series is dedicated to performance problems that are quite common but often have simple solutions.
      You can find lots on more advanced topics at developers.google.com!

  •  5 ปีที่แล้ว +33

    0:17 The unclosed script element made me slightly uncomfortable.

    • @binuavin
      @binuavin ปีที่แล้ว

      Wait till you see the head tags at 01:42 😂

  • @ayushgangrade1
    @ayushgangrade1 5 ปีที่แล้ว +6

    Thank you @Google for explaining it in simplest of the manner. :)

  • @beto.aveiga
    @beto.aveiga 5 ปีที่แล้ว +3

    Small changes can make big differences. Very good explaining it. It's critical to keep this in mind when building pages. Thanks 👍

  • @shreyasd4663
    @shreyasd4663 5 ปีที่แล้ว

    Well this type of video actually helps beginner and intermediate to get the concept working in an easy to understand way.

  • @husnimarwan
    @husnimarwan 5 ปีที่แล้ว +1

    love that unregistered sublime mark on the top right corner

    • @benmorss5609
      @benmorss5609 5 ปีที่แล้ว

      Heh heh... I actually have paid for Sublime, but that's not reflected in this copy. Nice catch...

  • @LemonDust13
    @LemonDust13 3 ปีที่แล้ว +1

    can't thank y'all enough for this 💛 just what I was lookin for & answered the question I had

    • @yamansharma9344
      @yamansharma9344 3 ปีที่แล้ว

      Same here, my lead was asking me to load third party scripts after page load and i had no clue how to do that, now it makes sense

  • @petersen285
    @petersen285 5 ปีที่แล้ว +1

    Awesome video, but we also have to consider CSP (Content Security Policy) when using the extreme method. If it has been implemented in your site.

  • @MoritzFischer
    @MoritzFischer 5 ปีที่แล้ว +1

    Yes, please show more content like this. Very helpful. Thank you.

  • @sayedalimousavi6091
    @sayedalimousavi6091 2 ปีที่แล้ว

    The best advices I have ever faced. Thanks a lot!

  • @moshiurhowlader9564
    @moshiurhowlader9564 5 ปีที่แล้ว

    Very good tips and tricks. Thanks Google!

  • @benlu
    @benlu 5 ปีที่แล้ว +4

    Why don't you want to load things in parallel? That means people can't interact with your page until way later?

    • @frontendtony
      @frontendtony 5 ปีที่แล้ว

      I'm sure you noticed he mentioned that some critical scripts that site functionality depend on (like jQuery) should remain up top, including your 'main.js'

  • @PradeepSonawane8
    @PradeepSonawane8 5 ปีที่แล้ว +2

    Nice quick tip for beginners 👌👍

  • @IceMetalPunk
    @IceMetalPunk 5 ปีที่แล้ว +2

    How about using dynamic imports instead of appending script elements to the page?

  • @noobgrandmaster
    @noobgrandmaster 5 ปีที่แล้ว +4

    But there's something more like load the specific scripts when your in the specific section
    Like for example you have slider testiminonial on the bottom of the page, fire it when youre on that section i think in vue can handle it , they have something called lazy load components
    But it boils down how can you build something without library its much more efficient and easy to refactor

  • @LawZist
    @LawZist 5 ปีที่แล้ว

    Hope to see more of those !

  • @googleplexer
    @googleplexer 5 ปีที่แล้ว +2

    Wow it’s brilliant content! Simple and nice!

  • @looz727
    @looz727 5 ปีที่แล้ว +1

    I had seen many, way too many websites that loads alot of js first before the visual content
    Does website that loads visual content before js even exist in 2019?

  • @darthvader6436
    @darthvader6436 5 ปีที่แล้ว

    /oo 2:39 this whole of bunch of code can be writen using js, and array to build the tags on the DOM... if you want to see the source load the file as source where the html is displayed...

  • @abubakr9796
    @abubakr9796 5 ปีที่แล้ว +1

    Random unrelated recommendation of the year award

  • @OvidijusR
    @OvidijusR 5 ปีที่แล้ว +116

    Almost 2020 and you guys still showing jquery?

    • @moneyharry
      @moneyharry 5 ปีที่แล้ว

      He just showed that as an example.

    • @BrunoDeAngelis
      @BrunoDeAngelis 5 ปีที่แล้ว +23

      Well it's reasonable, considering jQuery is still present in 74% of all the websites in the world.

    • @topaz-rn
      @topaz-rn 5 ปีที่แล้ว +1

      What's better?
      I mean, isn't it easier to use jQuery rather than vanilla? I'm new in web development, so some enlightenment would be great.

    • @vcoppolecchia
      @vcoppolecchia 5 ปีที่แล้ว

      jQuery is still out there in a lot of projects, I think it's good to see examples of this kind. Not everything has yet been moved to vanilla js.

    • @codelucky
      @codelucky 5 ปีที่แล้ว +4

      @@topaz-rn jQuery is middle class. Poor man's quick solution to look rich.

  • @canarslan12
    @canarslan12 5 ปีที่แล้ว +6

    Extreme part should not be used as it is in video. sometimes, some cdn or anything else might not work temporally and at that time, window.load event is not fired or really late. it means that our js file will not work. keep that in mind. I think it also applies to defer tag but not sure

    • @vcoppolecchia
      @vcoppolecchia 5 ปีที่แล้ว

      I think I've solved the issue you're talking about: poll the document (with setTimeout) for document.readyState === 'complete' and only then load the scripts dynamically as the extreme method says. But...
      Remember to clearTimeout! 😄

  • @xali2008
    @xali2008 5 ปีที่แล้ว

    most of the web apps these days use javascript frameworks like ReactJs VueJS ... for rendering HTML and javascript is the first thing you should load.

  • @Terranova339
    @Terranova339 5 ปีที่แล้ว

    What application is he using to measure that Network Performance/Speed?

  • @CodingPhase
    @CodingPhase 5 ปีที่แล้ว

    Great presentation like always

  • @NOALNOM
    @NOALNOM 3 ปีที่แล้ว

    This is Great! But how can implement this on Elementor sites via code snippets? Thanks again for sharing!

  • @CyberQuickYT
    @CyberQuickYT 5 ปีที่แล้ว

    Also it prevents errors such as document is not defined and so

  • @IlpoOksanen
    @IlpoOksanen 5 ปีที่แล้ว +4

    A better tip for improving page performance would be to delete jQuery and trackers - less code takes less time to load, who would've thought?

    • @FunctionGermany
      @FunctionGermany 5 ปีที่แล้ว

      unfortunately not a choice for many devs in companies. i'm glad that those that see this video will at least consider the methods here and might make their sites a bit faster.

  • @saisreenivas2227
    @saisreenivas2227 5 ปีที่แล้ว +1

    Thanks a lot for sharing a knowledge

  • @Arron__
    @Arron__ 5 ปีที่แล้ว +11

    Yes Google, tell other people to optimize their code so that you can continue to hog all of the RAM.

  • @benjaminguzman9047
    @benjaminguzman9047 5 ปีที่แล้ว

    Is the extreme level same as using require.js or similar to load js code before it's needed instead of loading it after the page loads?

  • @travelmoustache
    @travelmoustache 5 ปีที่แล้ว +9

    I find it odd that in 2019 we show jQuery load event and script tags where most of the apps we make are behind some level of framework or even a vanilla js project with things like smart prefetching, preload and code splitting

    • @benmorss5609
      @benmorss5609 5 ปีที่แล้ว +1

      These frameworks and techniques are common. The goal here, though, was do something that was universal.

  • @darthvader6436
    @darthvader6436 5 ปีที่แล้ว +1

    1:48 one ☝️ thing i don’t use to close a tag /oo the thing is as the Genius Darth Vader /oo i reverse the tag to close it like this and my badorus genusity Go further is that i write latin or english latin by swipping the characters and write the characters from right to left. The cursor go from right to left to write the ending head tag, and then i switch to left to right writing, this solve the problem for all time and save in all html files the slash / for billions of files to eternity... if we still there..

  • @MrVecheater
    @MrVecheater 5 ปีที่แล้ว +1

    Bloatware devs explain why their software is so slow so others don't do the same mistake

  • @daniilosmolovskiy7602
    @daniilosmolovskiy7602 5 ปีที่แล้ว

    Good tips, thanks!

  • @namakudamono
    @namakudamono 5 ปีที่แล้ว

    I tried adding defer and async attributes to the script tags. Loading performance improved, but I noticed that most of the scripts stopped working or became unreliable. Any ideas?

  • @prakashgiri6820
    @prakashgiri6820 3 ปีที่แล้ว

    This is awesome.. and so much fun..

  • @SanNico
    @SanNico 5 ปีที่แล้ว

    Meanwhile, when using gmail or youtube studio you get a blank screen for several seconds before anything starts.

  • @georgehossa
    @georgehossa 5 ปีที่แล้ว

    but when the script have to call image server API, and need DOM element data attributes to catch the image ID?

  • @darthvader6436
    @darthvader6436 5 ปีที่แล้ว

    /oo 5:00 well this is a design issue, we need to make an afterloading() method to load those scripts that will do something else like displaying images whatever... /oo i really should recommend you to report this problem to the fondation of html consortium w3c..... HTML6 is time for it...

  • @zahovic5959
    @zahovic5959 5 ปีที่แล้ว

    Thanks

  • @HashimWarren
    @HashimWarren 5 ปีที่แล้ว +9

    Extreme Plus - don't load a script until a user has interacted on the page

    • @conoman5415
      @conoman5415 5 ปีที่แล้ว +5

      *coughts in single page application*

    • @jayaram.ramanarayanan
      @jayaram.ramanarayanan 5 ปีที่แล้ว

      Hashim Warren Not a good user experience if considering various scenarios.

    • @benmorss5609
      @benmorss5609 5 ปีที่แล้ว

      That is indeed more extreme. And you can do it! Just, as people point out, it happens at the cost of slowing down your site's reactions to user actions.

  • @amarg26
    @amarg26 4 ปีที่แล้ว

    What if I want to pass more than one js file in 3rd extreme case, how to pass it?

  • @wakeupcoders
    @wakeupcoders 3 ปีที่แล้ว

    Great video thanks for this amazing video it helped alot

  • @himbary
    @himbary 5 ปีที่แล้ว

    Amazing, good job!

  • @vatsalhirpara5869
    @vatsalhirpara5869 5 ปีที่แล้ว

    Great video!

  • @paszysznik
    @paszysznik 5 ปีที่แล้ว +18

    Why im the only person who has this in recomended?

    • @Shogoeu
      @Shogoeu 5 ปีที่แล้ว

      Because you're the only one that needs to fix their pages.

    • @pelic9608
      @pelic9608 4 ปีที่แล้ว

      I guess Google analyzed your website and... 😏

  • @prnk139
    @prnk139 3 ปีที่แล้ว

    Very Good!!

  • @digitzero3613
    @digitzero3613 5 ปีที่แล้ว +16

    Extreme++: Just throw Error 404 on each user request.

    • @TheddunTOSS
      @TheddunTOSS 4 ปีที่แล้ว

      Or just remove all the unnecessary bullshit from all the websites.

    • @SnaKops
      @SnaKops 3 ปีที่แล้ว

      That's a big brain time

  • @realcartoongirl
    @realcartoongirl 5 ปีที่แล้ว

    thx google person

  • @mohammadkermani2987
    @mohammadkermani2987 5 ปีที่แล้ว

    Good one

  • @tharindudilshan5175
    @tharindudilshan5175 5 ปีที่แล้ว +2

    Chrome development tools❤️❤️❤️❤️❤️❤️😇😘

  • @adiorthotos
    @adiorthotos 5 ปีที่แล้ว +3

    Why, oh why, would the Chrome Dev channel promote the use of jquery in the year 2019 when we have all these modern native Web APIs like Query Selector??

  • @thinketh2408
    @thinketh2408 3 ปีที่แล้ว

    Wow thabks

  • @leskoding
    @leskoding 5 ปีที่แล้ว

    superb

  • @DivineZeal
    @DivineZeal 5 ปีที่แล้ว +3

    Quick summary: learn asynchronous JavaScript.🙏🏿✌🏿

  • @PiotrWas
    @PiotrWas 5 ปีที่แล้ว

    Nice one! :)

  • @hobbyturystaSEO
    @hobbyturystaSEO 3 ปีที่แล้ว

    nice

  • @yobrosam8813
    @yobrosam8813 5 ปีที่แล้ว

    I heard jarvis in the begginning

  • @zuest696
    @zuest696 5 ปีที่แล้ว +1

    +1 for Using JQuery

  • @darthvader6436
    @darthvader6436 5 ปีที่แล้ว

    /oo? What 4:45 an event handler to the load event /oo whats for thats hacking... i never used jquery i don’t understand it /oo i don’t need it i built everything with js functions that i understand... /oo? And why you don’t tell them to make you a preload method to add the scripts into the header.
    Load() {
    preload();
    ....

  • @begga9682
    @begga9682 5 ปีที่แล้ว

    *Hides in any javascript framework*

  • @nanotech7431
    @nanotech7431 5 ปีที่แล้ว +1

    Who is better jQuery or Vuejs.js tell me how ?

  • @oussamasethoum2755
    @oussamasethoum2755 5 ปีที่แล้ว

    This is what they don't teach you on bootcamps :)

  • @sivispacem1631
    @sivispacem1631 5 ปีที่แล้ว

    Sometimes, html page is empty until js will be loaded 😐

    • @yocheeseify
      @yocheeseify 5 ปีที่แล้ว

      Use defer in your script tag

  • @SXsoft99
    @SXsoft99 5 ปีที่แล้ว +5

    Or you could go old school, and put your scripts at the end of the dom

  • @Itachihandyman
    @Itachihandyman ปีที่แล้ว

    I Don't get it!!!

  • @novelnouvel
    @novelnouvel 5 ปีที่แล้ว

    i always uses the extreme one. but i never know that what i am doing is the fastest one.... its just becomes behaviour from the very beginning i learn JS 🤣

    • @benmorss5609
      @benmorss5609 5 ปีที่แล้ว

      That's nice. I rarely see that technique in use!

  • @toneko_
    @toneko_ 5 ปีที่แล้ว +2

    this would be super useful if we were in 1930

  • @Shogoeu
    @Shogoeu 5 ปีที่แล้ว

    Loading scripts "on load" kinda looks bad to me. Just personal opinion, don't eat me alive for it.

  • @curt1s19
    @curt1s19 5 ปีที่แล้ว

    OPTIMIZE, in title

    • @IceMetalPunk
      @IceMetalPunk 5 ปีที่แล้ว

      Nope, the Brits spell it with an S :)

    • @jimbolino
      @jimbolino 5 ปีที่แล้ว

      en.wikipedia.org/wiki/American_and_British_English_spelling_differences#-ise,_-ize_(-isation,_-ization)

  • @sogiita
    @sogiita 5 ปีที่แล้ว

    Nice :v

  • @juanmamenendez
    @juanmamenendez 5 ปีที่แล้ว

    What about preload and prefetch ?!? and Jquery?? really....

  • @pelic9608
    @pelic9608 4 ปีที่แล้ว

    jquery?
    \*checks video's publishing date*
    jquery? really? 😄
    Seriously though: If you are concerned about your JS taking too much time to load, start with not using jQuery!

  • @darthvader6436
    @darthvader6436 5 ปีที่แล้ว

    /oo 3:07 why are you moving the scripts into the body /oo? I always find this weired and against html logic /oo but people do this anyway, this is an html infraction to the html laws of w3 /ioo yes mr Bernlee /oo http is trash but html is good...

  • @Almighty_Flat_Earth
    @Almighty_Flat_Earth 5 ปีที่แล้ว +1

    No wonder vscode is not used.. we hate vscode..

  • @spacetimekiddo
    @spacetimekiddo 5 ปีที่แล้ว +1

    Noob google uses jquery boo boo

    • @viansyahm3136
      @viansyahm3136 5 ปีที่แล้ว +1

      yeah. and after that they show how to do it with plain javascript.