I really think this is a common problem for many sites with AJAX list content. Therefore, give an example on some of the most popular (think about the scale) websites and their solutions:
Google Images
If you choose images.google.com and you are looking for anything, for example. "guiness", you will see a page full of results (in fact, the images are loaded with ajax, not the html code, so the page has a fixed height), and when scrolling at the bottom there is a button "Show more results"
. This may be the solution to one of your problems, but is it really necessary that the button be at the bottom, for example, the 10th page? I really think that this is usually a good solution for the convenience of using pages and memory leaks, but it really is not a necessary parameter, as we can see in:
Facebook
Facebook Newsfeed is another story. There is a "Show more posts"
button, but I really donβt know exactly when it is displayed, and the next page of messages is not loading. Once I had to load 10-15 pages of messages, only scrolling. And you know that Facebook posts have videos, photos, AJAX comments, and much more Javascript that take up a lot of memory. I think that they managed to do this after a lot of research, how many users scroll down to the bottom.
Youtube
Youtube has "Load more videos"
on every page, so the solution is basically similar to Google, except that Google displays the entire html of the page and just scrolls the image when scrolling.
Twitter
Twitter supports endless scrolling. Yes, they can do this because the tweet is 140 characters and they donβt need to worry so much about memory. After all, who wants to read more than 1000 pages of tweets when loading a single page. Thus, they do not have a button for "load more"
, and they are not needed.
So there are two solutions:
- Use infinite scrolling (you have to consider how much content you download and how rich it is)
- Use Button:
"load more"
Most of all you should not delete already loaded contents of the list.
Currently, all Javascript and Javascript have garbage collection , so it is very difficult to unload the DOM (if it has Javascript and not plain text) and you can remove the Garbage from Javascript. This means that you will not free all allocated memory from the downloaded content from the browser.
Also think about your requests, why do you need to download something again that you already downloaded in first place. It requires a different server request, which means a different database request, etc.