Ok, so we established the problem, let’s look for the solution.
… you did not register your spinner / loader to all the events (see below for details). Meaning that when you press “back” in browser then there is no loader and there still is a “white between-page”.
You have probably registered your loader to a click even, not to URL change event.
Yep, it’s only registered on specific clicks, but add it to pressing back would be just a matter of few characters of js code. Like really few. But you can only see this when you simulate very slow connection in you browser setting.
But in general that’s the problem with this solution - on different PC it can behave differently and maybe on slower PC little white flash can appear. The solutions just tries to minimize the “white flash” to minimum, but you can be never sure how the browser behaves. If there can’t be any white flash at all, the OPA/Ajax is the only solution, because it has no redirects. You can’t really control how browser handles loading the new page. You can only tune it a bit.
The solution from the blog has 3 parts
- Show spinner when moving to other page (it’s registered on specific links) - pure jQUery - moving, fading actual content and showing spinner. Waiting for the browser to redirect to new page
- This was the nasty part - when browser jumps to a new page, the new background and spinner MUST show right away. No delay. To achieve this, it wasn’t possible to just show some normal page which makes usual requests to JS files, css files or waiting for some code on the bottom of the page. So for this reason, if you look to the code, there is very slim head with non blocking loading of JS files via head.js library (it was great that time) and right after the opening body element there is this code
<div id="pozadi" style="position: fixed;top: 0; background: url('/img/body-pozadi2.png') fixed; min-height: 100%; height: 100%; width: 100%; opacity: 0.5; z-index: 2;"></div>
Css in the HTML, which is bad practice but it’s super fast and the browser displays it right after the previous page is gone.
3) Then the real page is loaded with opacity 0 and fade in or otherwise else animated in when loading is finished.
So you could actually use this approach - just have to bring in bigger spinner
I know how to register JS/CSS assets within the page. I don’t know how to register “global on click” or “global on load” event. So no matter what triggered new page to be loaded – spinner appears.
Here it’s important to say one thing - your question actually isn’t Yii related at all. It’s pure JS/CSS thing. Yii doesn’t care about those thing - which is good.
I know how to display SVG (or regular) image without iframe. I don’t know how to animate SVG without iframe. The original page (form where my customer took this requirements) uses iframe just for that purpose only (to animate gear-like SVG animation). Hence the question. If animating (actually: rotating) SVG objects is possible without iframe then iframe is not needed.
Ok, you can officially forget about iframe. Iframe is absolutely different technology, it has absolutely (like really) nothing to do with svg or animations. If you want animate something, you do it via css or JS (css is better). Putting svg to iframe doesn’t make the svg spin.
The reason why it was like that on the old site is (I guess) fact, that on the iframe page, there was the whole combo - svg and css for animation. So the page only loaded iframe where was the svg alerady spinning. Which is just silly solution. So - no more iframe.
So what you should/can do, if you can’t/don’t want to use SPA.
You can use the solution from the blog
- Register spinner overly to some actions (clicks, back button, …), wait for browser to load new page
- On new page mage sure you show the overlay spinner again as soon as possible - it must be the first thing on the page in pure HTML
- When the rest of the page (set to opacity 0) is loaded, animate it to opacity 1 and hide the spinner overlay.
Done.
Or you can use the Yii Pjax, which is again - pure html/css/js component, it’s not even a part of Yii3 because of that. Pjax helps you avoid the reloading of new pages entirely, because it can make all the clicks be ajax calling. It can even modify your url without reloading the page. It really can look like SPA, but it’s not, it’s just simple ajax.
Then you only need to only catch the moment when the pjax starts and ends and show/hide you overlay. This shouldn’t be so difficult, but you will have to look to the docs (GitHub - yiisoft/jquery-pjax: pushState + ajax = pjax and Pjax, yii\widgets\Pjax | API Documentation for Yii 2.0 | Yii PHP Framework) and use Events I guess.
Great thing with pjax is, that you don’t actually have to refresh the whole page, but only some part, but your overlay can still cover the whole page. So it can be somehow hybrid and looks really a lot like SPA.
But no matter if you chose first, second or totally different solution - it’s a matter of html/js/css - no Yii needed here.