流星加载脚本,CSS专用于页面 [英] Meteor load scripts, CSS specific to pages
问题描述
我目前遇到的问题是,我想只能执行特定的脚本和CSS文件,因为如果在错误的页面上执行,它会在浏览器控制台中产生错误。
The problem I'm currently experiencing is, that I want to be able to execute only specific scripts and CSS files, because if executed on a wrong page, it produces errors in the browser console.
我使用铁路由器为Meteor只有基本的代码,使其工作。现在,有没有办法发送脚本作为参数,所以它只加载我想要的网页加载的那些。
I'm using "Iron router" for Meteor with only the basic code to make it work. Now, is there a way for me to send scripts as parameters, so it only loads the ones I want the page to load?
推荐答案
p>总之,没有。 (Yet。)
In short, there isn't. (Yet.)
如果您有错误,您可能有错误的代码结构。有些方法可以在需要时执行代码 - 您应该可以查看 template.rendered
和模板。创建
回调,以及铁路由器控制器。
You probably have a wrong code structure if you've got errors. There are ways to execute code only when it's needed - you should probably take a look at template.rendered
and template.created
callbacks, as well as iron router controllers. However, that's for execution - everything is loaded on the beginning.
这就是说,你在技术上可以 使用 require.js
动态加载一些脚本。但这抵消了Meteor的大部分优势。使用Meteor也很难正常工作。
That being said, you technically could use things like require.js
to load some scripts dynamically. But this negates most of Meteor's advantages. It's also quite difficult to make it work properly with Meteor.
这篇关于流星加载脚本,CSS专用于页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!