0
我使用rxjs如按照打字稿所有的JavaScript文件:避免加載
import {Observable} from "./rx/Rx"
var main =() => {
$(".ui.dropdown").dropdown();
$(".left-half").backstretch(["../images/lotus.jpg"]);
var source = Observable.range(0, 3);
var subscription = source.subscribe(
x => {
console.log("Next: ${x}");
},
err => {
console.log("Error: ${err}");
},
() => {
console.log("Completed");
});
};
$(document)
.ready(() => {
main();
});
和文件結構
加載網頁,它需要25.42s,這是可怕的。我只使用Observable
對象,所有庫都將被加載。
如何防止長時間加載?
更新 對於後端我使用ASP.NET核心和tsconfig文件看起來如下:
{
"compilerOptions": {
"module": "amd",
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es6",
"outDir": "../wwwroot/js"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
而且require.js使用(佈局模板):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - IndustryCloud</title>
<environment names="Development">
<link href="~/lib/sui/semantic.css" rel="stylesheet" />
<link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment names="Staging,Production">
<link href="~/lib/sui/semantic.min.css" rel="stylesheet" />
<link rel="stylesheet" href="~/css/site.css" />
</environment>
</head>
<body>
@RenderBody()
<environment names="Development">
<script src="~/lib/jquery/jquery.js"></script>
<script src="~/lib/jquery-backstretch/jquery.backstretch.js"></script>
<script src="~/lib/sui/semantic.js"></script>
<script src="~/lib/require/require.js" data-main="../js/signin.js"></script>
</environment>
<environment names="Staging,Production">
</environment>
</body>
</html>
縮小和捆綁銷售將做的工作。 –
你在你的項目中使用什麼構建系統? – semanser
人們經常用AMD裝載機解決這個問題。看例如http://requirejs.org/ – Meeh