How to get glitch live reload to work with a page other than the main index.html?


#1

I’m editing a file (any other html file than the main actually) in this project: https://glitch.com/edit/#!/intro-to-html-css and when the live preview reloads, it always takes me back to the /

Is there a way to get it to load the current file, or do I have to work around it with a script and some localstorage magic?


#2

Not at the moment - it always reloads the root url.

You can open a tab and enter the url manually, it won’t reload but it won’t go back to the root url all the time either.


#3

I figured that’d be the answer, so I wrote a hacky script to work out the navigation.
But glitch could take the current file and if it’s a html file, reload the window to that location. Should be a 1 line change in the code. If glitch is opensource, I could do that.


#4

Hi @naugtur,

Unfortunately it’s not that easy, since there is not a one-to-one mapping between html files and pages on a web site. Definitely not a 1-line change in the general case :slight_smile: it might be possible for static websites though, so we’ll look into that!

Thanks for your suggestion :slight_smile:


#5

I’d say for the case of a static site (or a set of training examples like mine) the best simple improvement would be to open the current html file when live preview is clicked and then reload the same url instead of / on any change anywhere.
So the end user can decide what to view.

A separate button for live preview of current file would also work.

Thanks for your attention! Keep up the good work!


#6

a big part of the difficulty here is that browsers prevent us from having that much control over what is opened in a new tab/window, for security reasons.


#7

I know all about it. I’m a JavaScript developer and I do browser security too. But it’s a window in the same top level domain and you’re controlling the code there, so you could inject code to communicate over postmessage. On the other hand, I appreciate the fact you don’t.

I think a useful feature could be conjured out of just the ability to override the URL in the window.


#8

Hi @naugtur,

Unfortunately it’s not on the same top level domain :frowning:


#9

right. missed that.
Anyway, injecting a script should work if you decide to go with that.
No pressure though.