If you are a website developer you are familiar with ready-to-use web templates, programming frameworks, and content management systems (CMS). Such solutions "out of the box" make the web-mastering a convenient and simple process.
But very often there is a task to add custom scripts to a web-site bypassing CMS or other non-standard way. Especially if you do not have full access to the source code of the system. The task becomes very difficult if the website is built using an outdated code or an abandoned framework.
The best principle in software development is the same as for medicine:
Primum non nocere (Do not harm)
Therefore, the best way is to make your own code independent of the environment. Then add small and simple (in one line) injections to the working code base. In the embedded code, check the existence of your own variables, try to call only the standard language functions.
Choose the proper method to change the website context. You should select from simple to complex:
- printing new html blocks as a text
- call custom function that generates new content
- include the script files directly
- add own framework scripts into every old files
And never do the following:
- edit old/cms code directly
- rewrite all code using other programming language
- re-create website using some modern CMS
Happy webmastering 🙂