• Resolved auludag

    (@auludag)


    hi,

    while adding a JS code, if i choose linking as external, I get error:

    Uncaught SyntaxError: Unexpected token <

    such code is below.

    <script src="https://example.com/bugsnag-3.min.js"data-apikey="XXXXX"> </script>

    but if I add as inline, the error disappears.

    Should i add JS code as a HTML code if i want to add external?

    • This topic was modified 8 years, 9 months ago by auludag.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author SilkyPress

    (@diana_burduja)

    Linking an external JS should be done as a HTML code. Your code example is a piece of HTML code that links a JS code.

    If you read the default comments in the editor on the “Add HTML Code” page, then you’ll see an example similar to yours.

    Thread Starter auludag

    (@auludag)

    thank you. what is your personal opinion about internal vs external? would you suggest adding js codes inline or external speaking for WordPress? How performance would be affected for the plugin or site?

    Plugin Author SilkyPress

    (@diana_burduja)

    I usually use inline linking for small pieces of codes (10 lines or less) and external linking for bigger JavaScript codes.

    If it is a small piece of code, then it doesn’t make sense to let the browser create another connection with the server. It is more economical to write the JavaScript it directly in the HTML.

    If it is a bigger piece of code, then it’s better to let the browser create another connection with the server and afterwards cache the linked file. You don’t need to do anything for the browser’s cache of JavaScript files, this is done automatically.

    Thread Starter auludag

    (@auludag)

    Thank you for reply.

    According to your last reply, I think I should call scripts above who is used for calling a JS files externally. Though they seem only 1 line, they are used for calling JS files from some other site, and that JS that is called is huge – i mean above maybe 100 lines.

    I hope my approach is correct.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Syntax error if linking external?’ is closed to new replies.