How can I apply new changes when edit JS file in production?

AI-generated summary

Mạnh_Danh is having trouble applying changes to a JavaScript file in a Docker container on their VPS. They tried restarting the unicorn service, but it didn’t work. In contrast, changes made locally are applied instantly upon page reload.

Merefield suggests deploying the changes as a Theme Component, providing links to guides on the topic (Developer’s guide to Discourse themes and Splitting up theme JavaScript into multiple files).

Mạnh_Danh asks if there’s a way to rebuild JavaScript and see the changes instantly, like in a local environment. Merefield explains that there are four options for making persistent changes: maintaining a fork, creating a plugin, using a Theme Component, or submitting a pull request to the core. They recommend using a Theme Component for front-end changes.

After struggling for four hours, Mạnh_Danh finds that restarting Docker solves the issue, but Merefield cautions that the changes will be lost if the system is rebuilt. Pfaffman advises following Merefield’s advice and creating a Theme Component to avoid future issues.

I made some changes in JS files inside docker container on my running VPS. How can I apply new changes? I tried sv restart unicorn but it wasn’t work.

P/s: When I edit in my local computer, it apply instantly when I reload the page.

Deploy it as a Theme Component

I changed these files, can it possible to apply as a theme? Could you give me more details about that?

Thanks.

So there’s no way to re-build JS and it reflect instantly, like in local environment?

If you want managed and persistent changes to core code that live beyond a rebuild you have four options:

  • (maintain a) Fork (forget it, nasty amount of maintenance) - you’d only do this if you didn’t know about the next three options or were too lazy to learn about them :sleeping_face:
  • Plugin (Ruby & Rails, CSS, Javascript, templates & assets) - front end and back end.
  • Theme Component (JavaScript, CSS, Templates and assets) - front end only.
  • PR to core! :wink:

For you Theme Component appears to be the right approach. Put the time in to learn how to use them and you will be rewarded.

It may initially look like extra hassle but they are super convenient and you can update, enable and disable Theme Components online without rebuiding. Very handy! Currently the only main limitation they have is a lack of test support iirc.

After 4 hour struggling with it, I suddenly restart docker and it works!

Thanks for your support, Robert! :smiling_face_with_three_hearts:

Yes but the changes will be wiped out if you rebuild.

You’ll be sorry if you don’t follow Robert’s advice and create a theme component.