Home › Forums › JavaScript › Idea: Putting all javascripts into one script
- This topic is empty.
-
AuthorPosts
-
May 13, 2014 at 8:03 am #170020
mevaser
ParticipantI am working on a website that has lots of features which my boss wants. The problem as you can imagine that, I have this problem:
“Render-blocking JavaScript and CSS in above-the-fold content”
So got me thinking, if there was a way to create a plugin that will grab all those scripts and make them into one, so it reads only one script. May be there is already one I am not aware of.
Cheers,
May 13, 2014 at 8:04 am #170021Paulie_D
MemberA Plug-in?
Doubtful…but you can do it manually…and most of us do.
May 13, 2014 at 8:22 am #170024dyr
ParticipantGrunt or Gulp, both are task runners and can concatenate blocks of scripts or styles. Also you might consider placing your JS files before the closing </body> tag instead of in the <head> if that’s where they currently are.
http://gruntjs.com/
https://css-tricks.com/grunt-people-think-things-like-grunt-weird-hard/
https://css-tricks.com/video-screencasts/130-first-moments-grunt/http://gulpjs.com/
https://css-tricks.com/getting-started-gulp/May 13, 2014 at 1:11 pm #170060dyr
ParticipantPart of what TheDoc is alluding to, and a motivation for not concatenating large 3rd party libraries, is caching and code volatility. It’s likely that larger 3rd party libraries will be updated less frequently so it makes sense to leave them separate in order to leverage caching better on those files. It’s also likely, but not guaranteed, that the other custom scripts in your page may change more frequently (due to updates, etc.) and therefore will need to be cache-busted more regularly. Separating code by how frequently it may change is a smart technique that allows your site to be better optimized when served to the user.
May 13, 2014 at 1:36 pm #170063Rohithzr
Participant@dyr true, on my latest project i am actually using cookies.js and have placed my (some combined js) and other js before </body> and making cookies of most JS and CSS which are unlikely to change
May 14, 2014 at 3:42 am #170161Senff
ParticipantIf you’re working with a WordPress site (looking at your avatar, you might), you can use the W3 Total Cache plugin, which consolidates and minifies all your Javascript files into 1 large JS file, and does the same with CSS.
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.