Craigerson

Motorcycles, Blogging, Development, & More

  • Home
  • Blog
  • Links
  • Contact
  • About

Delay Page Load using JQuery

Last updated on January 2, 2018 By Craig Leave a Comment

I had a situation where I wanted to delay the load of my page, until all content was loaded.  The problem was, I was making a call to a PHP routine that would build a dynamic XML file that I was using to build a Spry data set.  Yeah, Yeah, I know, Spry right.  Don’t worry, working to move everything over to jQuery. Anyway, if you are looking for a simple solution to delay page load using JQuery, read on…

The Problem

Anyway, everything was working fine, but there was a slight flicker when the page loaded.  The PHP in this external call created a record set based upon my query, and simply looped through the records to build the XML file. So on initial load of the page, the page was displayed with everything but my data from the database, and once the Spry data was created the page was loaded with that data.  From the user’s experience, I would see the initial page, without any of the dynamic data, and then a split second later my dynamic data was loaded.

My goal was to clean up the user experience, and hold off loading the page until everything was ready (including the dynamic data).  I ended building a solution that would delay page load using JQuery, and it’s working better then I was initially hoping.

The Solution

What I ended up doing was hiding both Content and Footer DIV’s when the DOM was loaded, upon Window load I ended up showing both those DIV’s with a slight delay.  The end user result was a blank page with just my body and header information displayed, and then the content slid in from the right with all dynamic data loaded.  It’s actually a better effect that what I was using initially.

//Hide the footer on this page so we don't get the flicker prior to the XML data being loaded

$(document).ready(function() {
  $(".content").hide();   
  $(".footer").hide();
}); 
$(window).load(function() {
   $(".content").show(500);
 }); 
//Go create the XML DS that will be used as part of SPRY on this page 
var dsAdvisor = new Spry.Data.XMLDataSet("XML Data/xml-advisor-list.php", "root/row");

 

It’s pretty self explanatory.  The (window).load function will show the “content” div after a 500 ms delay.  By calling out an explicit delay, you will get the effect of having this div “slide in” from the right of the screen after the delay you call out.  This 1/2 second delay gives me time to make the call to the XML file, build the Spry data, load it to the page, all before it’s displayed to the end user.

A simple solution to delay page load using JQuery.

 

Filed Under: Development Tagged With: JavaScript, Jquery

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • My First NFT Collection (Free NFT Offer)
  • Pests Michigan vs Florida
  • Amazon has Launched their Rakhi Store Just Before Raksha Bandhan 2021, and the Deals are Great
  • Sourdough Recipe Calculator
  • My New Homebrewing Hobby

Categories

  • Blogging
  • Development
  • Featured
  • Misc
  • Motorcycle Monday
  • Motorcycles
  • NFT
  • Technology
  • Tuesday's Triumph

Legal Stuff:

I declare that I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com.

Tags

Ace Beginner Motorcycle Bell Blog Index buell blast chrome CloudFront css Custom Bike customize Custom Menu Custom Thruxton Daytona exhaust Fender Eliminator Kit foot peg gas gas mileage gas tank capacity Genesis gift ideas gloves harley davidson JavaScript Jquery Maund FEK moment of truth Motorcycle motorcycle helmet motorcyclist gift ideas Newchurch Plasti Dip Prose Theme range riders edge speed and strength Starter Bike Street Triple Thruxton Triumph triumph bonneville triumph bonneville handling Triumph Thruxton W3 Total Cache Winterization

[footer_backtotop]

Copyright © 2023 Craigerson - All Rights Reserved