How do you maintain Version Control of JS Code?

Hey there fellow Experts.

This is a problem I’ve faced frequently and was wondering how others manage it. I’ve often had issues with changes I make to the JS Code in the Builder settings get saved and then disappear the next day when I open the app. This happens especially when I have other collaborators on the app who also work on the backend.

Although I understand why exactly this is happening, I was wondering if anyone has tips as to how they maintain this? I do copy the code to a local file and push to a git repo but does any one have a better solution?

1 Like

Hi Arjun - as you are probably aware, the builder is not multi user so this would be a reason for JS disappearing.:blush:

1 Like

Hey Carl. Yes I’m aware that that’s why it’s happening. I remember reading it on Knack docs as well.

I understand that in that particular scenario, it is unavoidable. I’m still curious on finding if someone else has a better method of maintaining versions of their code once they’re done with an update…

1 Like

You may find that my good friend @Johnny_Parsons_86 may be able to help as he is a coder and I’m not :blush:

1 Like

Hi @Arjun and @CarlHolmes,

I have come across this previously but think you just have to be careful and make back ups on a local machine and Git repo’s.

I have two Idea’s you could explore

  1. This is the most elaborate but it might be worth exploring and creating a Chrome extension that can copy your code to a Git Repo. Have not explored this myself but Chrome extensions are very cool and easy to set up with a manifest.json file.

  2. Have external JS files for each person and use Lazyload in the head of the Javascript. This means one person manages the code in knack and can copy and paste the new code over a bit like a approving the work being done and there for avoiding the issue entirely. Only downside is the code on each script lazyloaded could take a bit longer to load.

Hope this help
Johnny

@Johnny_Parsons_86 both great ideas. May be I should look into developing the Chrome extension. :slight_smile:

hi! in case it helps:

  1. we never allow simultaneous building on the same app. a frustrating constraint, i know

  2. for code changes, we track custom JS/CSS in a github repo. We test code changes in a copy of the app, then branch/review/merge the code in the repo before copy/pasting it to the production app.

i agree with @Johnny_Parsons_86 that lazy-loading code from external files is an interesting idea. In which case you could manage your version code completely in a Git repo with your own deployment process.

Hope that helps.

Hi Arjun. Here’s how I do it.

I created a framework using webpack and it combines all of the files and directories into 1 main.js file. These files are pushed to gitlab. Then it saves the project to an s3 bucket and provides me with a CDN. I have a different cdn URL for each branch of the repo. The CDN is injected into the project in the JS section of the Knack app. My team and I just have to push via git cli and it updates the Knack project automatically.

1 Like