lloyd
lloyd

Reputation: 1181

Including All Scripts In Separate File

Making a site and I have a number of scripts piling up. I was thinking to myself it might be better to have a separate file to 'include' all my scripts without the clutter in my main html code.

Is this possible? What are some of the styles / methods people use for such a thing?

Upvotes: 1

Views: 101

Answers (2)

Destination Designs
Destination Designs

Reputation: 683

You may want to look into using HTML5 Imports using web components (http://webcomponents.org/) and polymer (https://www.polymer-project.org/1.0/), html imports and polyfill are native in chrome and then use simply use provided scripts for browser compatibility in IE and FF.

Upvotes: 1

Anchor
Anchor

Reputation: 1371

browserify, webpack and requirejs are currently some popular bundling libraries.

Alternatively, you can simply concatenate all of your scripts into one file either manually using something like the cat command in your terminal, or automatically, by using npm or a task runner like grunt or gulp then just include that file in your html. The benefit of using something like npm, gulp or grunt is that you can automatically watch your files for any changes, and when changes occur, it will concatenate all your various javascript files together for you.

Upvotes: 4

Related Questions