简体   繁体   中英

Multiple javascripts solution

I Have created a flatfile based cms. PHP and jquery mostly. It is very dynamic and easy in use. I have 3 javascript includes for juery and other functions. This is for the main cms files. So that is quite allright.

But i have written multiple plugins/addons for he cms, also jquery and php, guestbook, comments, rating system, album galleries, site search,.... The problem is that each plugin has javascripts included. And i need to include all scripts in the head part of my main cms in order for the plugin to work on the cms. Now all javascripts get loaded every time the page reloads or if u click a link. That gives many http requests wich slows the cms down. About 15 javascrip files are included in the head now

Is here a way i can load only the needed javascript files and not all of them with a function of some kind.

i tried to compress all the javascript into one file, but that gives errors...

I hope my question is clear in my bad english :) thx for any response

The tool you are looking for is called grunt.

http://gruntjs.com/

You have over 2000 packages for doing many things and one of them in concatenation and minification.

grunt-contrib-cssmin grunt-contrib-uglify grunt-contrib-concat the list goes on an on, but check 'em all here.

https://github.com/gruntjs/grunt-contrib

grunt is a little confusing the first time you see it, but there are heaps of resources for it and also heaps of stackoverflow examples.

Once you go grunt you never go back!

I'd think you can merge all javascript files and then minify it. are you using double function names or do you have javascript code outside of functions? maybe that is what is throwing up your errors.

would leave you with only one request to retrieve all your javascript functions , and you would only need to minify / compress one file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM