문제

I'm experiencing the documented bug where webkit browsers render the page incorrectly on first load because the javascript is executing before the css has finished downloading (due to them being downloaded in parallel).

While a quick refresh fixes the look of the page, that solution is inadequate for my problem (I run command-line utilities that take screenshots of our pages, but these utilities don't have the option to "refresh" a page before taking the screenshot)

Does anybody have any suggestions or solutions for ensuring that the css-include is loaded in it's entirety before the javascript-include and inline-javascript are executed?

Thanks! -Dan

EDIT-- Not using a library. Just good 'ol javascript.

도움이 되었습니까?

해결책

If you are using a library I think most of them allow you to do this. It's easy with jQuery, if not you can use a <script defer="(x number of second)">Function()</script> at the end of hte page. You may also consider moving the javascripts to the bottom of the page where possible. js Best Practices.

다른 팁

+1 for putting your scripts at the bottom of the page, also might try putting your script in the window.onload event:

<script >
function myCode(){
// do something
alert('test');
}
window.onload = myCode;
</script>

I'm not 100% sure whether the onload event will wait until the .css file is loaded though. but it's easy to try.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top