我知道已经发布了几个这种性质的问题(即 this ),但是没有找到可靠的解决方案。从表面上看,Meteor 目前缺乏动态加载/呈现不同 UI JavaScript(即 uilang )或每个模板的 CSS 文件的能力。在我的应用程序中,我有一些模板需要特定的 JS 库和 CSS,而不是其他模板。
例如:
user.html requires -> uilang.js, user_ui_code.js, userstyle.css
admin.html requires -> uilang.js, admin_ui_code.js, admin_style.css
我需要根据请求的路由(即 example.com/user
或 example.com/admin
)来呈现/加载每个 js/css 文件,对于不同的背景颜色、过渡等。Meteor 文档指出:
Files in /public are served to the client as-is. Use this to store assets such as images. For example, if you have an image located at /public/background.png, you can include it in your HTML with or in your CSS with background-image: url(/background.png). Note that /public is not part of the image URL.
因此您会认为将所有 js/css/images Assets 公开并在 head
中静态调用所需文件会解决问题。相反,似乎 JS(以及 CSS)文件被连接起来,并且无论您在哪条路线上,它们都同时运行,因此重叠代码。我不确定我是否遗漏了一些明显的东西,或者这是 Meteor 中的一个实际问题?
感谢您的帮助。
最佳答案
Meteor doesn't yet support lazy/on demand loading of resources.该功能在路线图上为 "incremental loading" .
与此同时,看看numtel:publicsources和 numtel:privatesources ,它允许您为延迟加载资源创建包,有或没有身份验证。
关于javascript - 使用 Meteor 为每个模板动态加载 JS/CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28332032/