Should I use miniature or regular versions of jQuery plugins during development and deployment?

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

Now, when I pack the application and deploy it, I would rather switch to the mini versions of the plugins. The only way I know this is to have both versions on hand and then manually change all the links in my views (I use MVC) to point to minified versions, then package and deploy. Ideally, I will minimize (and possibly confuse) my own javascript files.

Does anyone know of a more efficient and effective way to develop using non-mined plugins (for easy reading) and deploying using mini versions (for better performance)? Any articles you could point me to these conversations? I am new to how to handle javascript deployment, and could possibly improve on best practices.

Thank.

+5
source share
2 answers

I always use mini versions of 3 party JS if I don’t need to delve into this ... In any case, you could write an html helper that inserts the correct script name based on some configuration (maybe debug vs release). ..

You would have something like:

<%= Html.IncludeJQuery() %>

or if all your scripts comply with the same convention (.min.js for the mini version), then the helper that inserts '.min' into the script you pass is in the release

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

Update:

Html- - Mvc HtmlHelper, ActionLink, BeginForm, EditorFor .. ( albiet static), Html.MyMethod.... :

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);
    }
}

, ( , etcetc.etc.)

IsDebuggingEnabled web.config , , ...

+4

, Rails . , .

, :

# resources.yml
# example config file

development:
    jquery_url: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js

test:
    jquery_url: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js

production:
    jquery_url: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js

, .

RESOURCES = YAML::parse('resources.yml')[CURRENT_ENVIRONMENT]

, , , . <%= yield %> , .

# application.html.erb

<!DOCTYPE html>
<html
<head>
    <script src="<%= RESOURCES['jquery_url'] %>"</script>
</head>
<body> <% yield %> </body>
</html>

- CURRENT_ENVIRONMENT (, ), . API , .

+1

All Articles