doutuan4361 2011-08-26 04:54
浏览 44

too long

I have an external javascript file that uses the getScript() function to run another JS file.

I have those all on static.mydomain.com. (I'm new to setting up CDNs)

getScript() doesn't seem to allow cross-domain requests because my HTML is on domain.com. But then I tried using relative paths according to this post: Dynamic URLs in CSS/JS

It works for CSS but does not work for JS (specifically within the getScript() function). What's going on here? What are some ways to mitigate this problem when dealing with CDNs?

  • 写回答

1条回答 默认 最新

  • duanquan1876 2011-08-26 05:50
    关注

    The getScript method actually makes an ajax call, hence the reason it's not working. Unless you need access to things like 'was the script successfully found' and the like, it's better to just write up a quick method like...

    function addScript(source, domain) {
        $("head").append("<script src='"+ (domain ? domain + source : source) +"'></script>");
    }
    

    That will just add scripts to the head of the page, and let you add an optional domain to point to in case you want to change it up.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题