A general question. There are sites with different errors in the code (syntax errors in js, html). Usually, after errors, the browser does not process the scripts going below, or they somehow work incorrectly.

Question: Is it possible to guarantee the operation of your own script, connected by a file on this page, despite these errors?

  • no, guaranteed - no - Grundy

3 answers 3

I know only one way. It is necessary that your script be placed before the rest of the scripts and executed before them (that is, your code should not have onload and the like).

    I recommend using Grunt . With it, you can make minified JS files and in its settings you can enable JS code validation.

    But this will not give you a 100% guarantee. There are many browsers, and if we take into account the features of JavaScript engines in them, then there are thousands and even more. It is better to manually check the performance in the most frequently used browsers of your clients.

    • I can achieve 100% of the work of my script, but I can’t be sure that there are no errors on the site where people insert the script - Skywave
    • one
      @Skywave Then it seems that you are not dealing with your own problems . This is the problem of those who use incorrect scripts. - Makarenko_I_V

    Depends on the level of your access to the system:

    If full access - write correctly.
    If only to connect - write a competent module loader, loading all the scripts into try...catch , so the remaining files can be loaded and run without any special influence of the fallen out scripts ( JS very loyal to errors, this is horror and the gift of the Gods, depending on the look at this).
    If you can only say "Paste script#src and work" - you solve someone else's problem, so hammer.

    If it is extremely important that your customers receive your work product - hire technical support that will help solve these problems.