1

I have displayed a loading bar before the entire page is loaded on my website.
Here is the js which i am using
JsBin demo

Now the problem is when some one opens the web page , black background (css) appears and after 2-3 seconds loading bar shows the loading. Though this is the first script which loads on the website.
Why loading bar gets delay. How can i load it dynamically ?
This is my website . Script name is javatest.js
Sorry if i missed anything , i am just a newbie

wordpress user
  • 548
  • 7
  • 24
  • I think CSS loads asynchronously from JavaScript, because normally they don’t depend on each other. – Sebastian Simon Sep 13 '15 at 19:59
  • So is there anyway to load both java & css together? – wordpress user Sep 13 '15 at 20:02
  • 1
    Java is not JavaScript. What do you mean by “together”? If they load asynchronously, they already load together. If you want your JS to load before the CSS, you have to load your CSS _via JS_. – Sebastian Simon Sep 13 '15 at 20:04
  • Ohkay please can you tell me how to do that . CSS & JS in the above link – wordpress user Sep 13 '15 at 20:07
  • One of the answers at [this question](http://stackoverflow.com/q/14028113/4642212) may be helpful. Basically you just need to append a `` element with the URL to your CSS as the `href` attribute. You can do that at some specific point in your JavaScript where the loading bar finishes, for example. I’m still not quite sure how this is a _problem_, though. – Sebastian Simon Sep 13 '15 at 20:14
  • i did the same way as shown [here](http://stackoverflow.com/questions/574944/how-to-load-up-css-files-using-javascript/577002#577002) . But still the same delay – wordpress user Sep 13 '15 at 20:57

1 Answers1

0

Based on your comments it looks like you're after loading CSS via your JavaScript. This has been answered here. I'm not sure if this will work with JSBin or not, so I suggest you test this in notepad or something else.

Community
  • 1
  • 1
KswisDev
  • 11
  • 3
  • Yea I followed your link , Did the same way as shown in the answer , I could load the css from js but still loading bar shows up after 2-3 seconds. Still the same thing . – wordpress user Sep 13 '15 at 20:52
  • @wordpressuser Is your actual goal to _reduce the delay_ of the _loading bar first appearing_, regardless of when the CSS loads? – Sebastian Simon Sep 13 '15 at 20:59
  • Yes Sir , thats what i want , as soon as some one opens the page, he should see the loading bar. – wordpress user Sep 13 '15 at 21:02