doujuanqi2909 2017-07-26 17:11
浏览 50

如何加载某些javascript只在特定页面上延迟,而不是所有页面

I have a page(not post) in wordpress for ex: http://www.xxxxxx.com/how-we-do-proceed/

I am using lot of javascript in the site but above the page is not related to any cart or plugin. This page is very important for us in the term of SEO, so I want to load few of javascript as defer. for ex: a.js, b.js, c.js etc.

All javascript added via WordPress handler.

How can I do it? any example of code welcome.

  • 写回答

1条回答 默认 最新

  • duanbeng1923 2017-07-26 17:22
    关注

    I think you can do it with plain javascript like this:

    var tag = document.createElement("script");
    tag.src = "http://xxxxxx.com/js/a.js";
    document.getElementsByTagName("head")[0].appendChild(tag);
    

    Or, if you use jQuery, you can do it like this:

    $.getScript("http://xxxxxx.com/js/a.js");
    

    Hope it helps!

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器