dqwh1209 2010-04-24 11:18
浏览 49
已采纳

在HTML / PHP模板或单独的js文件中调用jQuery脚本的最佳方法是什么?

StackOverflow is telling me this is a subjective question, but I think it's a matter of fact!

I have a number of scripts that I'm using on different parts of my site. In terms of making fewer http requests, I know it's better to combine all of these scripts into one .js file. However, isn't a waste of time for a page to call a .js full of 10 or 15 different functions when it's only using one?

The other method I am using is to use PHP conditional statements...

<?php if( is_page() ) { > 
     $(document).ready(function(){
          ...
     });
<?php } ?>

What's the best method or comination of these methods?

  • 写回答

2条回答 默认 最新

  • drvjlec1767 2010-04-24 11:24
    关注

    I would say, provided you expect users to require the vast majority of these resources as they browse your site, taking the hit all at once isn't much of an issue.

    You need to make sure that your homepage loads quickly enough though, maybe consider a cut down script file for the homepage, and a fully bloated version for the other pages. Or separate out the truly required on every page features into a file that is included on the homepage, and the other features into an -extra file. Then include both files on pages which require them. The browser will already have cached the basic file from the homepage.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line