1

I can't seem to get the preloader (Query Loader 2) to load before everything else on the page. When I refresh the page the images in the full screen slider display block down the page, then the query loader starts. Is there a way to start the preloader before everything else on the page?

I use stack overflow alot and normally find the answer to my question but with my limited knowledge of javascript this one has got me stumped. Things I've tried: Putting the call to queryloader2 right at the top of the page in the header. Putting the call to the slider scripts at the bottom of the page so they load after the preloader. Changing the z-index of the preloader to higher than the slider. jQuery.getScript() which loaded the scripts in order but the slider still displayed block down the page and then the preloader started.

I'm thinking its to do with the load order but if you have any ideas as to what I'm doing wrong here your help would be much appreciated.

I've put a link to my site as I didn't know which piece of code to put on here and so you can see the way the preloader and slider load the wrong way round http://stavriaphotography.com

asked Mar 26, 2014 at 6:21

2 Answers 2

2

The site is quite heavy on external scripts. Here's how loading resources in browsers work:

Images are loaded asynchronously, this means browser doesn't wait for the image to load before continuing further down the DOM, however

JavaScript is loaded synchronously and you can not load the next one before the previous is loaded.

jQuery $(document).ready() function fires only when the DOM is completly loaded.

Here's what going on, on your site:

You load jQ and queryLoader in the head and prepare to call it when DOM is ready. The scripts in the footer take time to load and are delaying the $(document).ready() function call. In the mean time you have images in your body and since they are loaded asynchronously the browser begins loading them before the queryLoader is ready to execute.

The most simple solution in your case would be to move all the external scripts to your html header, however not a very practical one.

I'd suggest reading up a bit on JavaScript and splitting up you site into multiple files for faster loading.

Some pointers: jQuery.ajax() and Handlebars.js or if you really want to go crazy dive into Backbone.js with RequireJS for asynchronous javascript loading.

Hope this helps!

answered Mar 26, 2014 at 9:31
Sign up to request clarification or add additional context in comments.

1 Comment

This is very helpful and thank you for taking the time to answer. Have a great day!
0

Put Jquery Library first

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

then add your other JS files

answered Mar 26, 2014 at 7:14

1 Comment

Thanks for the reply but I already have that file at the top with the others loading after.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.