加载 javascript、EnhanceJS
是否可以加载像这样的 js 脚本,并用逗号分隔脚本:
<script src="/js/enhance.js,enhance.config.js" type="text/javascript"></script>
我正在使用 Filament Groups 渐进增强 javascript 库“EnhanceJS”,并且我正在尝试从他们的网站 www.filamentgroup.com 学习,该技术的使用效果非常好,另一个例子:
<script src="/js/jquery.js,jquery.plugins.js,common.js" type="text/javascript"></script>
当我尝试做同样的事情并在 firebug 中查看时,上面的代码就在那里,但仔细检查后,我收到一条错误消息“请求的 URL /js/jquery.js,jquery.plugins.js,common.js 无法”可以在此服务器上找到。
渐进增强对我来说非常陌生,我不确定我是否需要以特定方式设置我的服务器来处理这种加载 Javascript 的方法。
编辑:
在加载的 JS 文件中,它们有一个配置文件,用于加载其余脚本,如下所示:
/* Copyright Filamentgroup.com: EnhanceJS configuration for screen/mobile enhancements */
//common script dependencies
var baseScripts = '/js/jquery.js,jquery.plugins.js,common.js';
//check for mediaq support, base screen type on it
var screenMedia = enhance.query('screen and (max-device-width: 1024px)') ? 'screen and (device-min-width: 5000px)' : 'screen',
handheldMedia = 'screen and (max-device-width: 1024px)';
//call enhance() function, include relevant assets for capable browsers
enhance({
loadStyles: [
{media: screenMedia, href: '/css/screen.css'},
{media: handheldMedia, href: '/css/handheld.css'}
],
loadScripts: [
'http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js',
{media: screenMedia, src: baseScripts+',screen.js'},
{media: handheldMedia, src: baseScripts+',handheld.js'}
],
forcePassText: 'Enhanced version',
forceFailText: 'Basic version'
});
Is it possible to load js scripts like this with commas separating the scripts:
<script src="/js/enhance.js,enhance.config.js" type="text/javascript"></script>
I am using the Filament Groups progressive enhancement javascript library 'EnhanceJS' and I am trying learn from their website www.filamentgroup.com where this technique is used to great effect, another example:
<script src="/js/jquery.js,jquery.plugins.js,common.js" type="text/javascript"></script>
When I try to do the same and look in firebug the above code is there but on closer inspection I get an error saying 'the requested URL /js/jquery.js,jquery.plugins.js,common.js could not be found on this server.
Progressive Enhancement is very new to me and I am not sure if I need my server set in a particular way to handle this method of loading Javascript.
EDIT:
In the JS file that is loaded they have a config file that loads the rest of the scripts like this:
/* Copyright Filamentgroup.com: EnhanceJS configuration for screen/mobile enhancements */
//common script dependencies
var baseScripts = '/js/jquery.js,jquery.plugins.js,common.js';
//check for mediaq support, base screen type on it
var screenMedia = enhance.query('screen and (max-device-width: 1024px)') ? 'screen and (device-min-width: 5000px)' : 'screen',
handheldMedia = 'screen and (max-device-width: 1024px)';
//call enhance() function, include relevant assets for capable browsers
enhance({
loadStyles: [
{media: screenMedia, href: '/css/screen.css'},
{media: handheldMedia, href: '/css/handheld.css'}
],
loadScripts: [
'http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js',
{media: screenMedia, src: baseScripts+',screen.js'},
{media: handheldMedia, src: baseScripts+',handheld.js'}
],
forcePassText: 'Enhanced version',
forceFailText: 'Basic version'
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我之前将其作为评论发布,但我会将其作为答案发布,因为它看起来很合适。
HTML
元素不支持在一个元素中包含多个脚本。它在他们的网站上运行的原因是因为他们有一个 JavaScript 文件,字面意思是
enhance.js,enhance.config.js
,并且他们使用的所有其他脚本都类似。我猜测这些文件是在服务器端生成的,或者是使用某种编译器在幕后创建的。所有这些都不是在客户端完成的,因此您可以停止寻找 JavaScript 解决方案。只需像平常一样逐一加载脚本即可。
I posted this as a comment earlier, but I'll post it as an answer since it seems fitting.
The HTML
<script>
element does not support including multiple scripts in one element. The reason it works on their website is because they have a JavaScript file that is literally calledenhance.js,enhance.config.js
, and similar for all the rest of the scripts they use. I am guessing these files are generated on the server-side, or created behind-the-scenes using some sort of compiler.None of this is being done on the client-side, so you can stop looking for a JavaScript solution to this. Just load the scripts as you normally would, one-by-one.
这可能是使用 mod_concat。
This is probably concatenating the files on the server on-demand, using something like mod_concat.