I'm having some difficulty on settlin开发者_运维知识库g on an approach for loading additional data in an application that I am building. The app is a CMS in which a single page consists of many fragments--some reusable, others exclusive.
An example of an exclusive fragment might be a description/author meta tag, whereas a reusable fragment might be a list of links.
My current approach is to load the essential data that makes up the bulk of the page, e.g. Main body content, title,slug, dates (publish/expiration/modified). After that portion is loaded and the ui is ready, I load 2 additional datasets: a collection of metatags; a collection of fragments.
My confers are: 1. Scalability 2. Speed 3. Maintainability
Is my approach sound or should I consider another approach?
I am assuming that you are using AJAX for lazy loading mentioned above.
Is your approach sound? The answer to your question depends on how fast the entire page is loading (including the fragments). Your technique is used when we want to create the perception of the page is loaded so the user psychologically don't feel like waiting,
That technique is used when the entire page is deemed too long to load. As the measures of "too long to load" is subjective, let's consider 8 seconds as an example. If the entire page takes 8 seconds to load and partial page such as main body, etc takes 3 seconds, then it is wise to load those portion first so the user psychologically don't feel like waiting for 8 seconds.
As for your 3 criteria:
Scalability : Lazy loading would increase the number of http calls back to the server and thus introducing additional loads in terms of number of total calls to the server as well as the possibility of taking up the number of concurrent connections. As such, lazy loading introduce additional overhead to the servers. However, if your deployment environment is a clustered properly, it should not be causing any major problem for you.
Speed: This is back to what I said before. If your entire page load very fast then doing the lazy loading of the fragments could actually slow it down (in terms of total seconds) since you are making extra HTTP calls to the server. In this case, you are not helping the perception of the users as well. However, if the speed to load the entire page is long, then the technique make sense as it improve user's perception of speed even total time of speed loading is probably greater.
Maintainability: A good implementation would enable to choose between loading entire page and in fragments by few simple code. That would signify that you have written a maintainable and flexible code.
精彩评论