简体   繁体   English

多种JavaScript解决方案

[英]Multiple javascripts solution

I Have created a flatfile based cms. 我已经创建了一个基于cms的平面文件。 PHP and jquery mostly. PHP和jquery大多。 It is very dynamic and easy in use. 它非常动态并且易于使用。 I have 3 javascript includes for juery and other functions. 我有3个针对juery和其他功能的JavaScript。 This is for the main cms files. 这是用于主要cms文件。 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. 但是我为他的cms编写了多个插件/插件,还有jquery和php,留言簿,评论,评分系统,专辑库,站点搜索等等。问题是每个插件都包含了javascripts。 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. 我需要将所有脚本包含在我的主要cms的头部,以便该插件在cms上工作。 Now all javascripts get loaded every time the page reloads or if u click a link. 现在,每次页面重新加载或您单击链接时,所有javascript都会加载。 That gives many http requests wich slows the cms down. 这样可以使许多HTTP请求减慢cms的速度。 About 15 javascrip files are included in the head now 现在头部中包含大约15个Javascrip文件

Is here a way i can load only the needed javascript files and not all of them with a function of some kind. 这是我可以只加载所需的javascript文件的方法,而不是全部都具有某种功能的方法。

i tried to compress all the javascript into one file, but that gives errors... 我试图将所有javascript压缩到一个文件中,但这会产生错误...

I hope my question is clear in my bad english :) thx for any response 我希望我的英语不好我的问题很清楚:) thx任何答复

The tool you are looking for is called grunt. 您正在寻找的工具称为grunt。

http://gruntjs.com/ http://gruntjs.com/

You have over 2000 packages for doing many things and one of them in concatenation and minification. 您有2000多个软件包,可以做很多事情,其中​​之一是串联和缩小。

grunt-contrib-cssmin grunt-contrib-uglify grunt-contrib-concat the list goes on an on, but check 'em all here. grunt-contrib-cssmin grunt-contrib-uglify grunt-contrib-concat的清单不胜枚举,但请在此处全部检查。

https://github.com/gruntjs/grunt-contrib 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. 第一次看到grunt时会感到有些困惑,但是它有很多资源,还有stackoverflow示例。

Once you go grunt you never go back! 一旦发出咕unt声,就永远不会回头!

I'd think you can merge all javascript files and then minify it. 我认为您可以合并所有javascript文件,然后将其最小化。 are you using double function names or do you have javascript code outside of functions? 您使用的是双重函数名称还是函数之外的javascript代码? 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. 只会给您一个检索所有javascript函数的请求,并且您只需缩小/压缩一个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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