flash service

High_Performance_Web_Sites

Issue link: https://read.uberflip.com/i/1146286

Contents of this Issue

Navigation

Page 82 of 169

The Best of Both Worlds | 61 Dynamic Inlining http://stevesouders.com/hpws/dynamic-inlining.php Since every user starts off without the cookie, there has to be a way to bootstrap the process. This is accomplished by using the post-onload download technique from the previous example. The first time a user visits the page, the server sees that the cookie is absent and it generates a page that inlines the components. The server then adds JavaScript to dynamically download the external files (and set a cookie) after the page has loaded. The next time the page is visited, the server sees the cookie and generates a page that uses external files. The PHP code that handles the dynamic behavior is shown below: OUTPUT; } else { // If the cookie is NOT present, it's likely the component is NOT cached. // Inline all the components and trigger a post-onload download of the files. echo "\n"; echo "\n"; // Output the Post-Onload Download JavaScript code here. echo << function doOnload( ) { setTimeout("downloadComponents( )", 1000); } window.onload = doOnload; // Download external components dynamically using JavaScript. function downloadComponents( ) { document.cookie = "CA=1"; [snip...] ONLOAD; } ?> I didn't show all of the post-onload download JavaScript code (as indicated by "[snip…]") since that was included earlier in the "Post-Onload Download" section. However, I did show just enough to illustrate how the CA cookie is set in the downloadComponents function. This is the only change, but it's key to leveraging the cache on subsequent page views.

Articles in this issue

Links on this page

Archives of this issue

view archives of flash service - High_Performance_Web_Sites