我应该使用jQuery插件的精缩或常规版本的开发和部署过程中? [英] Should I use minified or regular versions of jQuery plugins during development and deployment?

查看:70
本文介绍了我应该使用jQuery插件的精缩或常规版本的开发和部署过程中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如许多人都知道,大多数的jQuery(或JavaScript,对于这个问题)的插件,你找到这些天可下载为两种格式定期code,精缩版,或两者兼而有之。为发展宗旨,我喜欢用插件的非缩小的版本,万一我需要设置一个断点萤火虫或通过它看起来的任何理由。

As many of you know, most jQuery (or javascript, for that matter) plugins you find these days can be downloaded as either regularly formatted code, minified version, or both. For development purposes, I like to use the non-minified versions of the plugins, in case I need to set a Firebug breakpoint or look through it for any reason.

现在,当我打包我的应用程序和部署它,我宁愿切换到插件的版本缩小的,对于效率的缘故。我知道这样做的唯一方法是手头上有两个版本,然后手动更改我的观点(我用MVC)的所有引用指向缩小的版本,然后打包和部署。理想情况下,我会污染减量(也许混淆)我自己的JavaScript的文件。

Now when I package my app and deploy it, I'd rather switch to the minified versions of the plugins, for efficiency's sake. The only way I know to do this is to have both versions on hand, then manually change all the references in my Views (I use MVC) to point to the minified versions, then package and deploy. Ideally I'll be minifying (and maybe obfuscating) my own javascript files as well.

有谁知道与非精缩插件(为便于阅读)发展和缩小的同版本(效率)部署一个更好的,更有效的方法?任何文章,你可以指向我谈谈吗?我是pretty新如何处理JavaScript的部署,并很可能刷上的最佳做法。

Does anyone know of a better, more efficient way of developing with non-minified plugins (for readability) and deploying with minified versions (for efficiency)? Any articles you could point me to that talk about it? I'm pretty new to how to handle javascript deployment, and could probably brush up on best practices.

感谢。

推荐答案

我倾向于总是用届党JSS的缩小的版本,除非我特别需要寻找到它...在任何情况下,你可以写一个HTML帮手中插入基于一些配置正确的脚本名称(可调试VS发布)...

I tend to always use the minified versions of 3th party JSs unless I specifically need to look into it... In any case, you could write an html helper that inserts the correct script name based on some configuration (can be debug vs release)...

您最终会得到这样的:

<%= Html.IncludeJQuery() %>

如果所有的脚本遵循同样的约定(.min.js的精缩版)做到这一点插入您传递是当发行脚本中的.min帮手

or if all your scripts follow the same convention ( .min.js for minified version) do a helper that inserts the '.min' on the script that you pass is when in release

<%= Html.IncludeCorrectVersionOfScript("jquery-1.4.2.js") %>

更新:

HTML辅助,是扩展方法,MVC的HtmlHelper类,你可以用它来发出ActionLink的,BeginForm,EditorFor等你基本上附加的新方法(只albiet静态)到该对象,以便你可以做Html.MyMethod。 ......针对此帮手会是一些这样的:

Html helpers, are extension methods to Mvc's HtmlHelper class that you can use to emit the ActionLink, BeginForm, EditorFor, etc. You basically attach a new method (albiet static only) to that object so you can do Html.MyMethod.... A helper for this would be some like:

public static class ScriptIncludeHelper
{
    public static MvcHtmlString IncludeCorrectVersionOfScript(this HtmlHelper html, string script)
    {
        if (!html.ViewContext.HttpContext.IsDebuggingEnabled)
            script = script.Replace(".js", ".min.js");
        var tag = string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", script);

        return MvcHtmlString.Create(tag);
    }
}

请注意,这是非常简化的版本(没有字符串的验证,etc.etc.etc。)

Note that this is very simplified version (no validation of the string, etc.etc.etc.)

现在您可以使用IsDebuggingEnabled或你的web.config配置或静态配置来定义,如果你要包括调试版本的最小化版本...

Now you could use the IsDebuggingEnabled or a configuration in your web.config or a static configuration to define if you want to include the minimized version of the debug version...

合这有助于

这篇关于我应该使用jQuery插件的精缩或常规版本的开发和部署过程中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆