Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

javascript - Detect a new page was added in an infinity scroll

I have an infinity scroll and I want to check when a new page is added to the DOM. Since I am a third party to the website I wanted to know which of the following methods is the best method performance wise in order to detect such change to the DOM:

  1. setInterval
  2. Mutation observer
  3. Scroll event
  4. Intersection observer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I can't describe with expert knowledge but let me tell you my opinion. I think the best option is using the scroll event and check window height every time the site is scrolled

setInterval is not a good option I think because if you set delay with long term, it would be shown has late response time or if you set delay with short term, the function is called lots of times even not necessary

And I'm not familiar with Mutation observer and Intersection observer but I know that both of these need to point to an element that is observed. It's okay if you know which element you have to watch but you are a third party. you have to check every time when the site is updated.

but Scroll event is doesn't have to point to an element and it will be called to a minimum.

I think the best option is using the scroll event and check window height every time the site is scrolled


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...