Best way to include JS files

What is the best way to include JavaScript files in Blocs?

Right now, I am manually uploading the minified JS files I need to my server, placing them inside the /js folder. Then in Blocs, I add code similar to the following, with an exact URL to the JS file…

Of course, than means I need to manage those files outside Blocs, but is it better or recommended to instead have Blocs upload those JS files by adding them as Header File Attachments in Page Settings?

I would let Blocs handle it. Also you probably want to add the js file in the header not the footer.

Some advantages, it creates the link for you, its easy to manage and it doesn’t full the code area up with lots of stuff if you’re using it a lot.

1 Like

Pete, it appears you are suggesting this…

  1. Include all external JavaScript files via Header File Attachments in Page Settings:

  2. Add individual links to included JS files in Page Settings > Add Code > Header:

  3. Put associated JS code in the Page Settings > Add Code > Footer:

The above steps mean Blocs isn’t fully handling things for the user insofar as the user must put the “script src” part into the Header manually. And that means knowing the URL(s) to the individual JS files you included via Header File Attachments.

No. I never suggest step 2. That would create a double entry.

But yes you would usually run the scripts at the end of the page.

Actually I re-read my post. I see where it was confusing. I was referring to your screen shot.

1 Like

So you are saying Blocs will perform step 2. for us anytime we add external code files via Page Settings > Header File Attachments.

Understood. Thank you.

1 Like