加载 javascript、EnhanceJS

发布于 2024-09-07 13:57:17 字数 1572 浏览 2 评论 0原文

是否可以加载像这样的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

后eg是否自 2024-09-14 13:57:18

我之前将其作为评论发布,但我会将其作为答案发布,因为它看起来很合适。

HTML

所有这些都不是在客户端完成的,因此您可以停止寻找 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 called enhance.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.

十秒萌定你 2024-09-14 13:57:18

这可能是使用 mod_concat

This is probably concatenating the files on the server on-demand, using something like mod_concat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文