有没有办法只在必要时加载JS和CSS?

时间:2021-12-26 09:47:17

We are rewriting a very large legacy Webforms .NET application. Ideally, I would like to have it completely as SPA, based on AngularJS, Bootstrap, and WebAPI. Obviously, the overall look and feel should be consistent across the application.

我们正在重写一个非常大的遗留Webforms .NET应用程序。理想情况下,我希望将它完全作为SPA,基于AngularJS,Bootstrap和WebAPI。显然,整个外观应该在整个应用程序中保持一致。

I have one big concern, however. There are many "rich" controls (calendar, table); not to mention light or shared controls like tooltips or tabs. These control libraries come with their JavaScript and CSS.

然而,我有一个大问题。有许多“丰富”的控件(日历,表格);更不用说光或共享控件,如工具提示或标签。这些控件库带有JavaScript和CSS。

The easiest way is to minimize and load all JS and CSS in index.html. But easiest isn't always the best. Even minimized, these libraries come up to a significant size, especially when over half of it is not needed. I realize that Web Components will allow such dynamic loading; but until then, should I go for more traditional MVC design, and go to the server for full page reload? Or with the power of today's desktops and browsers I am exaggerating the problem and should just load all the libraries upfront?

最简单的方法是在index.html中最小化并加载所有JS和CSS。但最简单的并不总是最好的。即使最小化,这些库也会达到相当大的规模,特别是当不需要超过一半的时候。我意识到Web组件将允许这样的动态加载;但在那之前,我应该去更传统的MVC设计,并去服务器进行整页重装?或者凭借当今桌面和浏览器的强大功能,我夸大了问题,应该只是加载所有的库?

2 个解决方案

#1


1  

In angularJS there is service called ocLazyLoad, I think using this you can load required js and css.

在angularJS中有一个名为ocLazyLoad的服务,我认为使用它你可以加载所需的js和css。

#2


1  

An $import.js is a tiny utility, that allows to control js/css/less files loading to the document when only it's necessary.

$ import.js是一个很小的实用程序,只有在必要时才允许控制加载到文档的js / css / less文件。

#1


1  

In angularJS there is service called ocLazyLoad, I think using this you can load required js and css.

在angularJS中有一个名为ocLazyLoad的服务,我认为使用它你可以加载所需的js和css。

#2


1  

An $import.js is a tiny utility, that allows to control js/css/less files loading to the document when only it's necessary.

$ import.js是一个很小的实用程序,只有在必要时才允许控制加载到文档的js / css / less文件。