N
N
Nube2018-03-10 12:44:49
go
Nube, 2018-03-10 12:44:49

Is it possible to arrange html loading without page reload using WebSocket?

Good afternoon. Is it possible to change templates dynamically without reloading the page. For example, when you click on a button, change the template to another one, or, more simply, change parts of the html page on the fly.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
rPman, 2018-03-10
@Nube

Not only possible, but necessary.
Two classic approaches
are page content generation, i.e. html is formed and placed in an element on the page, replacing the previous
one - the page immediately represents all the templates (unfinished pages) placed in hidden elements, then by pressing the button this template is supplemented with information and made visible.
Very often, the second method is more justified, it is more convenient to debug, but most likely the final result will be a combination of these approaches, when the main structure of the page is determined by the html itself, but the internal elements are completed by the script.
The normal approach is to store templates right there on the page in <script id='myTemplate' type='html/text'>....</script>, as a result, all the necessary templates will be loaded on the first page load, and cached, and in the future only data is requested from the server (via websocket or ajax), convenient, logical, fast and most importantly, the development logically separates the interface is handled by the browser, the data is handled by the server.

C
chromimon, 2018-03-10
@chromimon

It has nothing to do with the Go programming language that is indicated in your tags.
And it is related to the JavaScript programming language, but it is not indicated in your tags.

A
Abcdefgk, 2018-03-11
@Abcdefgk

Tyrts

R
Roman, 2018-03-12
@KirEv

https://github.com/gorilla/websocket
but if you have a similar question, maybe you shouldn't write this part in Go?
in fact, this is possible by implementing go-ws (server) + javascript-ws (client) + go (application server), the task itself is time-consuming, and requires appropriate skills, more details.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question