1

I'm thinking of the following two requests:

  1. Request 1:

    Load all static HTML, JavaScript, images, etc. the website framework so to speak. Then fire a second request to get dynamic content (say news items, latest posts).

  2. Request 2

    Send new HTML, JavaScript, images, etc. as required by dynamic content.

I'm expecting the first request to be cached for subsequent times a user visits the website, and thus to be a non-issue for returning users. But for first-time users should I maybe build the entire content server-side and send it together in one request? Since in the approach above, both requests need to be responded to in order for the user to be able to use the website.

Can I just leave it as two requests (easier for me to program, since I'm building single page app that relies on Ajax requests)? Or is there an easy way to build everything server side and avoid two requests the for first time users?

... but wouldn't that break the caching mechanism, since the same URL would return partially different content each time?

Is this a known issue with a known solution?

1

There are a couple things to consider here, at least when it comes to html content:

Method 1: Loading a portion of the site that will remain static for the foreseeable future is good when the same users are expected to frequent the website and SEO is less of an issue*. You also have some more control over perceived performance; the 'static' content can prepare the user with a basic UI that will lazily load content. I would recommend this method for websites that are more 'app' than 'site', where content is not the main reason visitors use your site.

Method 2: This is better for lots of one-time website visitors because there are less round trips to worry about. It is also better SEO because crawlers will see what the server generates*. It's also easier to maintain and update. I would recommend this for general-purpose sites that target a larger audience and contain a lot of mostly static content.

CSS and JS can be loaded and cached immediately. There are few reasons to load CSS or JS at any time other than when the website is first loaded.


*I don't have any sources handy, but I believe there has been some effort to make web crawlers capable of reading AJAX-generated content.

  • I was thinking in this direction, thanks for the confirmation. Also, I like the distinction between "app" and "site. – Rafael Emshoff Jun 3 '15 at 7:56
0

The first approach is the way to go - all links to the site resources are technically individual requests (though with http 1.1 they are made in a single connection with a small keep-alive). So subsequently requesting the dynamic resources is not any different. You might as well embed the link to the dynamic stuff in the html page and just let the browser run.

In addition, caching will apply if you read all resources as normal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.