I've been researchig this but haven't found much on the topic. What are the advantages and disadvantges of -
1) saving scripts externally
2) Embedding scripts

Would appreciate any insight on the topic!

Thanks -

5 Months
Discussion Span
Last Post by diafol

My thought is this is a system design question. And philosophical one too. One of my older apps at over 10 years old externalized a lot of things which kept me from changing the core code.

Example: The company was sold and the reports needed a change. The template was external so a file edit and done. A two minute job.

Not only that but saved a trip through product testing as the rule was if the .exe file changed then a full product test was required.

Now for the downside. It does leave the app open to beginners tinkering with the external plain text files.


It does leave the app open to beginners tinkering with the external plain text files.

That's funny. I externalized scripts (mostly Excel) because the users had to have write access in order to allow modification of the Excel data, but because the script was external it could reside in a read-only folder. Also, the Excel files were generational (a new one for each day) and having the code in each file would have been a nightmare managing code changes. With an external script I only ever had to modify one file.


One other advantage was that my scripts had to determine whether or not a given date fell within daylight saving time or not (transition days were especially painful because of the skipping or duplication of the transition hour). I had dozens of scripts that relied on this logic. When Bush (younger) changed the start/stop dates I only had to modify the DST logic class code in one place (the library that was included in all the other scripts). Other programmers had to modify/test code changes in dozens of applications.

Votes + Comments
Advantage: External.

As this is under webdev, I'm assuming you're referring to javascript, although it could refer to other languages too.

Placing a lot of javascript inside the actual html page is fine for testing purposes, but I'd suggest you place it in (an) external file(s). This means the code may be reused in different pages or at least can be conditionally loaded when/if required.
It also helps to organise your code - having a html page to throw all your various scripts into is horrible - you can place unrelated scripts into separate files.
You can also minify and gzip external files (you can also minify in-page scripts, but it sort of defeats the purpose).

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.