Here is how I handle it.
- Create a getkey.js file with a single getKey function.
- Include getkey.js in my HTML document(s).
- Add a .gitignore file to my project to exclude getkey.js
- Check the rest of the project into GitHub.
Create a getkey.js file
Here are the contents of my getkey.js file:
Of course, the return value will be your appropriate key.
Include getkey.js in my HTML document(s)
From script.js, I add code to call the getKey() function within a try/catch block. This will throw an exception if the script cannot find the getKey function (usually because it cannot find the getkey.js file). In this example, I output a useful error message in a DIV with an ID of "OutputDiv".
Here is the relevant code.
Add a .gitignore file to my project to exclude getkey.js
I want to keep the getkey.js file locally, but I don't want to check it into GitHub. Adding a file named ".gitignore" in the root of my project allows me to list any files or folders that I don't want to include in my GitHub repository.
Add the following line to the .gitignore file
Check the rest of the project into GitHub.
Once the above steps are completed, it is safe to check it into GitHub. The getkey.js file will not be checked in. When another user checks it out, they will need to create this file. I recommend creating a read.me file and pointing this out.
Even if they forget, the error message should give them an idea why their code is not working.
There are other ways to address this issue, but this way works for me.