Better Performance, Empty Elements Or Create And Destroy With Javascript?

前端 未结 4 853
误落风尘
误落风尘 2020-12-10 09:34

What would be better for performance, having many hidden elements on a page, or creating them and destroying them as they are needed with javascript upon request. For exampl

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 09:44

    IMHO you should do another kind of consideration, since is obvious that page load speed is affected by it's size in term of kb.

    • How to calculate web page size ?

      • HTML document file size (DOM elements);
      • File sizes graphics - including any background images;
      • Any included (JavaScript (.js), External Sheets (.css), SSI, PHP files etc) files sizes;
      • File sizes of preloaded data such as images;
      • Sizes of any multimedia content such as sound, video, Flash files etc. that are embedded in the web page;

    • what is the maximum size?

      • Each web page should not be more than 50kb. This will guarantee that web pages load in a matter of seconds.
      • iPhone won't cache components bigger than 25K.

    so, your problem is not properly the number of dom elements, you have a lot of things to do before care of hidden elements number! ;) hope this help


    REFERENCE:

    • Optimizing web pages- Maximum page size
    • Best Practices for Speeding Up Your Web Site
    • Using site speed in web search ranking
    • Javascript Performance
    • JavaScript Performance Best Practices

    TOOLS

    • Page Speed, the Web Performance Tool

提交回复
热议问题