我想定义一个这样的包:
bundles.Add(
new StyleBundle("~/style.css").Include(
//...
));
Run Code Online (Sandbox Code Playgroud)
如果捆绑包名称只是"~/style"这样,但是文件扩展名它总是返回404.我怀疑服务器在驱动器上搜索CSS和JS文件并忽略捆绑系统,但是我找不到其他人正在尝试在包名称中包含文件扩展名.这可能没有像URL重写这样的东西吗?
asp.net-mvc asp.net-mvc-4 bundling-and-minification asp.net-optimization
当我在发布模式下运行我的ASP.NET MVC 4应用程序时,捆绑包仍在输出未分隔和单独的js文件,而不是将其捆绑并缩小为更少的捆绑JavaScript文件.
有任何想法吗?
仅供参考,发布配置:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud) javascript asp.net-mvc asp.net-mvc-4 bundling-and-minification
我刚开始使用VS 2012 RC.我创建了一个包含母版页和单个Web表单的测试站点.目前,我正在使用此代码捆绑Styles网站上的整个文件夹:
Global.asax中
BundleTable.Bundles.EnableDefaultBundles();
Run Code Online (Sandbox Code Playgroud)
的Site.Master
<link rel="stylesheet" type="text/css" href="Styles/css" />
Run Code Online (Sandbox Code Playgroud)
问题:测试站点有一个站点级CSS文件,用于控制站点的整体外观.除了站点级CSS之外,每个页面都可以有自己的CSS定义.是否可以仅在site.css主页中包含该文件,然后在每个页面需要时有条件地将.css文件添加到包中?
我在后面的代码中尝试了这个Default.aspx但它没有用:
BundleTable.Bundles.Add(new Bundle("~/Styles/Default.css"));
Run Code Online (Sandbox Code Playgroud) 我正在尝试对一些.css和.js文件使用bundle minification.我的bundle配置如下:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/Modernizr").Include(
"~/Scripts/modernizr.js"
));
bundles.Add(new StyleBundle("~/TemplateContent").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-responsive.css",
"~/Content/prettyPhoto.css",
"~/Content/prettify.css",
"~/Content/flexslider.css",
"~/Content/iview.css",
"~/Content/style.css",
"~/Content/default.css"
));
bundles.Add(new StyleBundle("~/AppContent").Include(
"~/Content/bootstrap-tablesorter.css",
"~/Content/animate.css",
"~/Content/font-awesome.css",
"~/Content/jcarousel.css",
"~/Conten/overwrite.css",
"~/Content/sequence.css",
"~/Content/sequence.ie.css",
//more styles
));
bundles.Add(new ScriptBundle("~/TemplateScripts").Include(
"~/Scripts/modernizr-*",
"~/Scripts/jquery.js",
"~/Scripts/raphael.js",
"~/Scripts/jquery.easing.1.3.js",
"~/Scripts/bootstrap.js",
"~/Scripts/google-code-prettify/prettify.js",
"~/Scripts/jquery.elastislide.js",
"~/Scripts/jquery.tweet.js",
"~/Scripts/jquery.prettyPhoto.js",
"~/Scripts/jquery.flexslider.js",
"~/Scripts/iview.js",
"~/Scripts/jquery-hover-effect.js",
"~/Scripts/animate.js",
"~/Scripts/custom.js"
));
bundles.Add(new ScriptBundle("~/AppScripts").Include(
"~/Scripts/jquery.ticker.js",
"~/Scripts/jquery.contenthover.js",
"~/Scripts/jquery-ui-1.10.3.js",
"~/Scripts/datetimepicker.js",
"~/Scripts/jquery.metadata.js",
//more scripts
));
BundleTable.EnableOptimizations = true;
}
Run Code Online (Sandbox Code Playgroud)
当我将应用程序发布到服务器(godaddy共享虚拟主机)时,问题就出现了,我确实得到了一个缩小的输出,但是我在这些输出上得到403错误.
如果我订
BundleTable.EnableOptimizations = false;
Run Code Online (Sandbox Code Playgroud)
文件不会缩小,但页面具有正确的行为.
我有一个ASP.NET MVC4应用程序(我认为)自从一年前首次发布以来一直在使用JavaScript和CSS捆绑.在此期间,我们发布了大量更新,并且没有看到脚本传送出现问题的证据.
但是,通过我们最新的代码部署,我注意到服务的JavaScript不是最新的,并且无论底层脚本内容发生什么变化,脚本包请求中使用的查询字符串参数都不会更改.
我尝试在Visual Studio中重建解决方案,并验证修改后的脚本文件是否正确部署到服务器.我还明确地回收了IIS应用程序池并重新启动了服务器,但问题仍然存在.
有任何想法如何诊断或解决这个问题?
更新:刚刚比较了暂存和生产服务器,我注意到了行为上的差异.使用Visual Studio Web部署以相同方式部署两个服务器.登台服务器通过更新它在引用脚本包的URL中使用的哈希值,正确并立即反映脚本文件的更改.相反,生产服务器无法更新其捆绑哈希以响应脚本文件修改和/或更改脚本包的组成(即使在重新启动IIS或回收应用程序池之后).这表明该问题与生产IIS环境隔离,并且与我的代码更改或Visual Studio配置无关.
我的应用程序使用JSPM和SystemJS进行模块加载,并使用angular.
我的config.js文件有角度图,如:
"angular": "github:angular/bower-angular@1.5.8"
Run Code Online (Sandbox Code Playgroud)
所以,当我这样做时import angular from 'angular',我从config.js文件中指定的Path获取angular.js 文件.非常好.
现在要求是我想在应用程序中使用缩小的第三方javascript文件(angular.min.js).但是jspm 注册表中没有缩小的文件
所以我的应用程序的初始加载时间很长,因为有很多大文件,例如angular.js,browser.js等需要花费太多时间来加载.
我知道,我可以做一个jspm bundle递归缩小所有依赖文件,包括供应商的文件.但我的问题是:
1 -是否可以直接使用JSPM的供应商缩小文件(angular.min.js)?使用供应商的缩小文件而不是将它们缩小为自己是好的,不是吗?
2 -如果上面的一个不可能,那么我如何只捆绑我的应用程序特定文件并仍然能够使用(单独捆绑)minified angular.js文件?
这里推荐的方法是什么?
javascript angularjs bundling-and-minification systemjs jspm
我最近必须考虑一个新软件的部署方法,该软件是用以下代码编写的:
该软件将部署在160多台服务器上,分布在欧洲各地,其中一些服务器的互联网连接非常糟糕。
我做了一些研究,很多人明确建议 反对捆绑。主要论点是,原生扩展将因像webpack或 这样的捆绑器而失败rollup(剧透:这是真的,但有一个解决方案)。在我看来,这很大程度上是因为人们不关心这一点:作者对这个用例node-pre-gyp使用了几乎相同的词语。因此,通常情况下,我被告知要使用yarn install或同步node_modules/文件夹。
该项目是新的,但node_modules/文件夹已经超过 480 MB。使用 XZ 进行最大压缩后,我得到了 20 MB 的存档。这对我来说仍然太大了,而且似乎是对资源的巨大浪费。
我还看了以下问答:
node_modules/开箱即用。IgnorePlugins显得太过分了。TypeORM 还有一些单独的问答,但所有这些似乎都需要安装ts-nodeor typescript …
我了解如何使用asp.net的新捆绑和缩小功能.它们在开发过程中很有用.
在生产部署中使用它们有什么好处吗?如果您只是将捆绑/缩小的文件放在Web服务器上,系统会表现得更好吗?似乎整体而言,如果它们只是静态文件,则会运行更少的代码.
注意:我理解将js/css捆绑和缩小的好处.我只是质疑使用活动运行时进程在生产系统中生成这些文件的价值,而不是简单地将它们存储在磁盘上并将它们作为静态文件引用.
我们正在寻找到新的捆绑的功能,ASP.NET MVC 4,如果有任何优势,想知道捆绑CSS文件被从CDN服务?
有没有办法捆绑从ASP.NET MVC 4中的CDN提供的多个文件?这不起作用:
var cdnCssPath = "http://MyCdn/css/";
bundles.Add(new StyleBundle("~/Content/css", cdnCssPath)
.Include("~/Content/site.css")
.Include("~/Content/Test1.css")
.Include("~/Content/Test2.css")
.Include("~/Content/Test3.css")
);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我正在尝试使用此博客中描述的技术将嵌入式DLL资源添加到我的捆绑包中.
我在VirtualPathProvider下面创建了自定义.
public class EmbeddedVirtualPathProvider : VirtualPathProvider {
private Type _rootType;
public EmbeddedVirtualPathProvider(Type rootType) {
_rootType = rootType;
}
public override bool FileExists(string virtualPath) {
if (IsEmbeddedPath(virtualPath))
return true;
else
return Previous.FileExists(virtualPath);
}
public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart) {
if (IsEmbeddedPath(virtualPath)) {
return null;
}
else {
return Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
}
}
public override VirtualDirectory GetDirectory(string virtualDir) {
return Previous.GetDirectory(virtualDir);
}
public override bool DirectoryExists(string virtualDir) {
return Previous.DirectoryExists(virtualDir);
}
public …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc virtualpathprovider bundling-and-minification