Note that there are some explanatory texts on larger screens.

plurals
  1. POCan JavaScript be used to prefetch external CSS and JS files, ready for the next page on same website?
    primarykey
    data
    text
    <p>I am in the process of optimising a website, with the main aim of improving the overall download times of web pages. I have been applying as many of the techniques recommended by the Yahoo Developer Network's <a href="http://developer.yahoo.com/performance/rules.html" rel="nofollow">"Best Practices for Speeding Up Your Web Site"</a>.</p> <p>Now, the stats show that we have a lot of visitors that first access the website via:</p> <p>the stand-alone search engine page HTTP error handlers - i.e. our custom "404 Not Found” page other miscellaneous stand-alone pages</p> <p>Please note that these so-called "stand-alone pages” exist independently from the template system which is responsible for the layout and structure of the pages from the website proper. They have their own style sheet(s) and scripts (and therefore exist independently of the template system's CSS and JS files also).</p> <p>Now, these page types are more intermediary pages than content pages. A good example of their general purpose would be that of a <a href="http://en.wikipedia.org/wiki/Landing_page#Reference_landing_page" rel="nofollow">reference landing page</a>. I thought that it would be a good idea to use a technique like <strong>post-onload</strong> to “prime” the user's cache ready for their next move (which will nearly <em>always</em> be part of the main template system).</p> <p>The script by Steve Sounders is:</p> <p><strong><a href="http://stevesouders.com/examples/post-onload.php" rel="nofollow">post-onload.php</a>:</strong></p> <pre><code>&lt;script&gt; function doOnload() { // Do the downloading awhile AFTER the onload. setTimeout("downloadComponents()", 1000); } window.onload = doOnload; // Download external components dynamically using JavaScript. function downloadComponents() { downloadCSS("http://stevesouders.com/hpws/testsm.css?t=1388138263"); downloadJS("http://stevesouders.com/hpws/testsma.js?t=1388138263"); downloadJS("http://stevesouders.com/hpws/testsmb.js?t=1388138263"); downloadJS("http://stevesouders.com/hpws/testsmc.js?t=1388138263"); } // Download a stylesheet dynamically. function downloadCSS(url) { var elem = document.createElement("link"); elem.rel = "stylesheet"; elem.type = "text/css"; elem.href = url; document.body.appendChild(elem); } // Download a script dynamically. function downloadJS(url) { var elem = document.createElement("script"); elem.src = url; document.body.appendChild(elem); } &lt;/script&gt; </code></pre> <p>What I would like to know is this:</p> <p><strong>Is it possible to re-write the two functions that perform basically the same thing as <code>downloadCSS(url)</code> and <code>downloadJS(url)</code>, __without__ it actually being applied to the containing web page?</strong></p> <p>In effect, I am looking for <code>downloadCSS(url)</code> / <code>downloadJS(url)</code> functions that acts as a pre-load for the next web page's external CSS/JS files, which will behave much like the way the HTML5 spec intends the <code>@prefetch</code> attribute to be implemented). I basically want the files downloaded via <strong>post-onload</strong> to be in the cache ready.</p> <p>If not, any other suggestions on how to perform the same task would be amazing!</p> <p>Thanks in advance! </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload