Answer the question
In order to leave comments, you need to log in
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
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.
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.
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 questionAsk a Question
731 491 924 answers to any question