RequireJS文本插件错误地导入我的模板

时间:2015-08-21 18:18:29

标签: javascript text requirejs require requirejs-text

使用带有文本插件的require.js导入文本文件时,最终输出中缺少一些正斜杠,导致解析器因未封闭的块语句而失败。 JavaScript非常标准,看起来像:

define(['handlebars', 'some/dependency', 'text!some/text.html'], function (Handlebars, SomeDependency, text) {
    var MyView = Backbone.View.Extend({
        template: Handlebars.compile(text),
        // etc.
    })
})

导入有效,这意味着我从require获取数据,但我发现如果text.html的内容如下所示:

<div {{#if prop}}class="{{prop}}" {{else}} class="other-class"{{/if}}></div>

它无法正确返回。相反,我得到的是:

<div {{#if prop}}class="{{prop}}" {{else}} class="other-class"{{ if}}></div>

当它在一个html元素内时,它以某种方式丢失了if块的结束正斜杠。但是,如果我将其更改为:

{{#if prop}}
    <div class="{{prop}}"></div>
{{else}}
    <div class="other-class"></div>
{{/if}}

它正确回归。

现在,一个明显的解决方案是使用第二个范例,但我的所有模板都像第一个模板一样设置,并且它们在几天前(周,顶部)正常工作。

有人对可能导致这种情况的原因有任何想法吗?

现在我要查看提交日志,看看我是否能找到任何明显的东西,如果我发现了什么,我会在这里添加。

1 个答案:

答案 0 :(得分:0)

经过与各个团队的多次讨论,我们将问题缩小为由亚马逊实例中的Apache pageSpeed模块引起的。

此设置导致显示<head/>标记: https://developers.google.com/speed/pagespeed/module/filter-head-add

并且我不确定哪个特定设置可能是导致{{/if}}损坏的原因。

禁用mod后,问题得以解决。