用主页生成捆绑的js和css文件的机制是什么? [英] What are the mechanics of producing bundled js and css files with master pages?

查看:99
本文介绍了用主页生成捆绑的js和css文件的机制是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET Core项目,其中_Layout.cshtml主页面引用了站点范围的样式和js文件:

I have a .NET Core project in which the master page _Layout.cshtml page references site wide style and js files:

<link rel="stylesheet" href="~/css/site.css" />
<script src="~/js/site.js" asp-append-version="true"></script>

利用上述母版页的Index.cshtml页面引用了特定于页面的样式和js文件:

The Index.cshtml page, which utilizes the above master page, references page specific style and js files:

<link type="text/css" rel="stylesheet" href="~/css/landing.css">    
<script src="~/js/landing.js" asp-append-version="true"></script>

然后Contact.cshtml和About.cshtml也具有页面特定的CSS和JS文件。

And then Contact.cshtml and About.cshtml also have page specific css and js files.

将站点范围文件与页面特定文件捆绑在一起的正确方法是什么?
是否应该避免在母版页中引用任何内容,而只是在每个页面的.cshtml中引用捆绑的文件?

What is the correct method to bundle the site wide files with page specific files? Should I avoid referencing anything the in the master page and simply reference the bundled file in each page's .cshtml?

推荐答案

您可以在母版页中引用跨页共享的所有脚本和样式表。例如,您只能引用jquery。

You reference in your Master Page all scripts and Style Sheets you share across pages. For instance, you could reference only jquery.

您在页面中引用了该页面上特定使用的脚本和样式。

You reference in your pages scripts and styles that are used specific on that pages.

听起来很简单。

这篇关于用主页生成捆绑的js和css文件的机制是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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