The discussion revolves around calling a JavaScript function on every page change in Discourse, particularly in a Dockerized environment. Chmarus seeks advice on best practices for achieving this using JavaScript and Ruby on Rails. jordan.vidrine recommends using the plugin API, providing links to the developer guide and withPluginApi documentation. An example script is shared to log the current URL and page title on page changes, which can be added to the common/head_tag.html file via the admin panel at /admin/customize/themes/9/common/head_tag/edit. Chmarus then asks about best practices for editing files in a Dockerized setup, and jordan.vidrine confirms that direct container edits may work but suggests using the admin panel for safer modifications.
I would like to call a JavaScript function on every page change by the user.
I understand JS and Ruby on Rails code, but I’m not sure what is the best practice in Discourse to achieve that. I’d be grateful for any tips.
Depending on what you want to do this could be wildly varied, but to call a function, or do something on every page change by the user you could use the plugin API.
Thanks @jordan.vidrine for reply. I will check these resources. One other question, maybe more related to Dockerized version. Is there any best practice for editing files inside the container? May I just “get” into the container modify files and restart it?
For some instances I believe that should work. (I dont have much experience with Docker)
You can also edit certain css and html files, as well as <script> tags from the discourse admin panel when visiting your site at /admin/customize/themes/9/common/head_tag/edit.