JSON-LD
脚本Rich Card
SERP
尝试创建User-Defined Variable以及Tag本身使用的脚本时。使用GTM的Preview and Debug功能时。我收到以下错误:
此语言功能仅支持ECMASCRIPT6模式或更好:请声明。使用--language_in = ECMASCRIPT6或ECMASCRIPT6_STRICT启用ES6功能。
我理解......或者至少我认为我理解我需要告诉编译器
使用--language_in = ECMASCRIPT6或ECMASCRIPT6_STRICT
但我该如何做到这一点?
<script>
(function(){
// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name default.js
// @language_in=ECMASCRIPT6_STRICT;
// @language_out=ES5_STRICT;
// ==/ClosureCompiler==
"use strict";
let data = {
"@context": "http://schema.org",
"@type": "MovingCompany",
"name": "WDA Movers",
"logo" : {
"@type" : "ImageObject",
"url" : "http://wda-moving.online/images/logo.jpg",
"height" : 435,
"width" : 361
},
"address": {
"@type": "PostalAddress",
"addressLocality": "Eugene",
"addressRegion": "OR",
"postalCode": "97404",
"streetAddress": "411 Heywood Avenue"
},
"openingHours": "Mo-Su 7:00-23:30",
"priceRange": "$$$",
"telephone": "(541) 255-9876",
"url": "http://wda-moving.online",
"sameAs" : [
"https://www.facebook.com/wda.movers/",
"https://plus.google.com/+WDAMoversEugene/about?gmbpt=true&hl=en"
],
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": {{YELP_rating}},
"reviewCount": {{YELP_review_count}},
"bestRating": "5",
"worstRating": "1"
},
"review": {
"@type" : "Review",
"author" : {{YELP_reviews_user_name}},
"reviewBody" : {{YELP_reviews_excerpt}},
"reviewRating" : {
"@type": "Rating",
"ratingValue": {{YELP_reviews_rating}}
}
}
}
let richCard = document.createElement('script');
richCard.type = "application/ld+json";
richCard.innerHTML = JSON.stringify(data);
document.getElementsByTagName('head')[0].appendChild(richCard);
})(document);
</script>
如您所见,我已尝试将以下内容添加到上述脚本中:
// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name default.js
// @language_in=ECMASCRIPT6_STRICT;
// @language_out=ES5_STRICT;
// ==/ClosureCompiler==
"use strict";
这不起作用......任何人都可以帮助我吗?
答案 0 :(得分:2)
如果您查看asset-pipeline plugin,您会找到build.gradle
的以下示例:
assets {
minifyJs = true
minifyCss = true
enableSourceMaps = true
configOptions = [:]
minifyOptions = [
languageMode: 'ES5',
targetLanguage: 'ES5', //Can go from ES6 to ES5 for those bleeding edgers
optimizationLevel: 'SIMPLE',
angularPass: true // Can use @ngInject annotation for Angular Apps
]
// ... snip ...
}
当我将languageMode
中的minifyOptions
设置为'ES6'
时,错误消失,并在部署时提供正确的JavaScript。您当然也可以将assets.minifyJs
设置为false
以获得相同的效果。