I have static html files automatically generated and saved in S3. Sometimes a file reaches 2mb size. Is it possible to use javascript to fetch a part of an html file, display it and when user reaches bottom of page, fetches next part and so on?
I have static html files automatically generated and saved in S3. Sometimes a file
Share
This is totally possible – the idea is that you can pre-render “fragments” on the server, where each fragment represents a “subpage” of N articles or what have you. You then render the page with 0 (or 1) fragments, and send it to the client. When the client scrolls to the bottom, you simply request the next fragment (with AJAX) and append it to the end of the previous fragment. Keep doing this indefinitely.
The key point to understand is that each fragment is rendered statically on the server. Though the fragment may not be a complete HTML page in and of itself, they are “infinitely appendable” into an existing page. Part of the fun of HTTP (as opposed to full HTML) is that you don’t have to have a full HTML page for any fragment to be successfully served; you can think of the HTML as “boilerplate” that surrounds arbitrary chunks of additional, non-well-formed HTML (that become well-formed when placed inside your boilerplate).
Since AJAX is based around HTTP requests, you can ask for any arbitrary content. Heck, you can ask for your own custom markup as long as the Javascript that “catches” the response can format it in a way the browser can understand – namely, HTML, CSS, and JavaScript.