jquery - Fake loading/progress bar for slow non-Ajax page -
i'm developing site serves slow (up around 4 sec. loading time) pages due extensive database queries.
in order let users know new page loading (also prevent multiple clicks), i'm displaying div fake loading bar on page users clicked link slow loading page.
actually, showing fake loading div working good. dom of old page (with fake loading bar) still displayed when new page loading, means loading div shown until new page ready displayed.
this how it's done. html part:
<!-- link example execute javascript --> <a href="link/to/slow/page/" class="loading">slow page</a> <!-- full screen div gets displayed when clicking "loading" class link. --> <div id="dim" style="display:none; top:0; left:0; width:100%; height:100%; z-index:9999;"> <div id="loading"> <p>loading data, please wait...</p> <img src="loading.gif" alt="loading..." /> </div> </div>
javascript (jquery) part:
$(".loading").each(function() { $(this).click(function() { $("#dim").fadein(); }); return true; });
the problem is, if user clicks in browser (just tested ff 3.6) slow page, loading bar div still shown sometimes.
questions:
- is way design such fake loading bar?
- if yes, there way prevent browsers displaying div when going in browser's history?
thanks hints.
conclusion:
looks there's no easy way fake way. i'm going ajax data retrieval real loading bar.
if query optimized not run long wouldn't need fake progress bar.
however, you're dealing browser cache here, there's nothing can force browser show or not show unless page request done when hit back-button.
a hacky way of doing things check, ondocumentready, if #dim fadein visible , make invisible.
that way when click happens, starts displaying, , if hit button browser renders page, checks if it's visible "onready" , make sure it's invisible unless button/link clicked
Comments
Post a Comment