有没有办法从 SquishIt 中组合的 javascript 文件中删除哈希值?

发布于 2025-01-08 01:34:21 字数 732 浏览 2 评论 0原文

我正在使用 SquishIt 在 MVC 3 项目中合并和缩小我的 javascript 文件。我正在尝试创建一个离线cache.manifest,而编辑之间的哈希代码变化简直要了我的命。有没有办法删除附加到捆绑包中的哈希值?

我签入了 BundleBase.cs 类并看到 HashKeyNamed 方法,但不知道在哪里使用它。

这是我现有的组合方法:

@Html.Raw(SquishIt.Framework.Bundle.JavaScript()
.Add("~/js/libs/persistence.js")
.Add("~/js/offline.common.js")
.Add("~/js/offline.syncmanager.js")
// snip...
.ForceRelease()    
.WithMinifier(SquishIt.Framework.JavaScript.Minifiers.JavaScriptMinifiers.NullMinifier)    
.Render("~/js/offline_script.js"))

I'm using SquishIt to combine and minify my javascript files in an MVC 3 project. I'm trying to create an offline cache.manifest and the hash codes changing between edits is killing me. Is there a way to remove the hash that is appended to the bundle?

I checked in the BundleBase.cs class and see a HashKeyNamed method but can't figure out where I would use it.

Here is my existing method for combining:

@Html.Raw(SquishIt.Framework.Bundle.JavaScript()
.Add("~/js/libs/persistence.js")
.Add("~/js/offline.common.js")
.Add("~/js/offline.syncmanager.js")
// snip...
.ForceRelease()    
.WithMinifier(SquishIt.Framework.JavaScript.Minifiers.JavaScriptMinifiers.NullMinifier)    
.Render("~/js/offline_script.js"))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

澉约 2025-01-15 01:34:21

抱歉我参加聚会迟到了。

在最新版本中,捆绑包上有一个名为 .WithoutRevisionHash() 的方法,可以满足您的需要。这种方法实际上是由于此处提到的 Jacob 的拉取请求而应运而生。

该方法本身只是先前存在的名为 .HashKeyNamed() 的方法的包装器,可以使用空字符串调用该方法,正如他指出的那样,以实现您所追求的结果。希望新方法更直观/更容易发现:)

Sorry I'm late to the party.

In the latest version, there is a method on bundles called .WithoutRevisionHash() that will do what you needed. This method actual came into being thanks to Jacob's pull request mentioned here.

The method itself is just a wrapper for a previously existing method called .HashKeyNamed() that could be called with an empty string as he pointed out to accomplish the result you're after. Hopefully the new method is a bit more intuitive/discoverable though :)

念﹏祤嫣 2025-01-15 01:34:21

我不相信有办法。您可以在此处查看所有公共 API 选项: https:// /github.com/jetheredge/SquishIt/blob/master/SquishIt.Framework/Base/IBundle.cs

虽然它是 OSS,所以你可以随时分叉该项目并进行添加!

祝你好运。

I don't believe there is a way. You can see all the public API options here: https://github.com/jetheredge/SquishIt/blob/master/SquishIt.Framework/Base/IBundle.cs

It is OSS though, so you can always fork the project and make the addition!

Good luck.

绿萝 2025-01-15 01:34:21

我最近提交了一个pull,以便在SquishIt,但与此同时,我认为您可以通过创建自己的自定义 JavaScriptBundle 来实现这一点并使用HashKeyNamed() 方法。

public class NoHashJavaScriptBundle : JavaScriptBundle
{
    public NoHashJavaScriptBundle()
        : base()
    { }

    protected override string BeforeMinify(string outputFile, List<string> files, IEnumerable<string> arbitraryContent)
    {
        // Set the hash key to empty to keep it from being appended in Render.
        HashKeyNamed(string.Empty);

        return base.BeforeMinify(outputFile, files, arbitraryContent);
    }
}

然后在您的 _Layout 中您可以执行以下操作:

@Html.Raw(new NoHashJavaScriptBundle()
.Add("~/js/libs/persistence.js")
.Add("~/js/offline.common.js")
.Add("~/js/offline.syncmanager.js")
// snip...
.ForceRelease()    
.WithMinifier(SquishIt.Framework.JavaScript.Minifiers.JavaScriptMinifiers.NullMinifier)    
.Render("~/js/DontHashMeBro.js"))

I've recently submitted a pull for some better support of this in SquishIt, but in the mean time, I think you can pull this off by creating your own custom JavaScriptBundle and using the HashKeyNamed() method.

public class NoHashJavaScriptBundle : JavaScriptBundle
{
    public NoHashJavaScriptBundle()
        : base()
    { }

    protected override string BeforeMinify(string outputFile, List<string> files, IEnumerable<string> arbitraryContent)
    {
        // Set the hash key to empty to keep it from being appended in Render.
        HashKeyNamed(string.Empty);

        return base.BeforeMinify(outputFile, files, arbitraryContent);
    }
}

Then in your _Layout you could do something like this:

@Html.Raw(new NoHashJavaScriptBundle()
.Add("~/js/libs/persistence.js")
.Add("~/js/offline.common.js")
.Add("~/js/offline.syncmanager.js")
// snip...
.ForceRelease()    
.WithMinifier(SquishIt.Framework.JavaScript.Minifiers.JavaScriptMinifiers.NullMinifier)    
.Render("~/js/DontHashMeBro.js"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文