Skip to content

Latest commit

 

History

History
64 lines (44 loc) · 1.99 KB

资源引用.md

File metadata and controls

64 lines (44 loc) · 1.99 KB

资源引用

feather2中的资源引用非常简单,有几个规则:

  • 所有的script和link标签可以html的任意一个地方引用, 即使重复也没有关系, 需要即引用
  • 同目录下的资源,以相对路径引用(当然,你也可以引用解决路径,如果确保此目录以后不会迁移或共享)
div{
    background: url("./bg.png");
}
  • 以绝对路径的方式引入(注:此处的绝对路径是以项目目录开始,非文件本地机器上的路径)如:
<script src="/static/index.js"></script>
<link rel="stylesheet" type="text/css" href="/static/index.css" />
  • widget|pagelet|extends 引用
<!-- 引用 widget/common/header/header.html -->
<widget 'common/header/header'> 

<!-- 引用 pagelet/ajax/ajax.html -->
<pagelet 'ajax/ajax'>

<!-- 继承当前目录下的layout.html -->
<extends './layout'>

<!-- 继承项目目录下的page/layout.html -->
<extends 'page/layout'>
  • components 引用

注:此处可做简单了解,具体可见components

<!-- 先引用components/bootstrap/bootstrap.css,如果找不到该文件,则 直接查找 bootstrap/bootstrap.css文件 -->
<link style="stylesheet" href="bootstrap/bootstrap.css" />
<!-- 引用components/bootstrap/目录下*.json文件中指定的main文件 -->
<scirpt src="bootstrap"></script>

<script>
require.async('backbone');
require.async('/static/async.js');
</script>

以上为feather中,所有的资源引用方式,可尝试static目录下新增async.js, 然后在index.html中,直接引用

feather中,默认会帮助开发者进行脚本的位置优化,带有src的script标签会默认放置在</body>标签的上方, link标签会被放置于</head>结束标签的上方

如果希望某些js资源出现在顶部,则可以使用head属性指定即可:

<script src="a.js" head></script>

同时feather还支持fixed和ignore2个属性, 分别表示不优化资源位置和仅预览模式下收集资源的功能