最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get the version of underscorejs used - Stack Overflow

programmeradmin5浏览0评论

I'm building a widget which would be used in different eCommerce sites.

As i'm using underscorejs library, i need to see if underscorejs exists in the parent site and if so what version.

If underscore is already defined in the site and if the version matches with the one i used. I would inturn use their own defined underscore and not make a CDN call to load underscorejs for my widget.

I'm building a widget which would be used in different eCommerce sites.

As i'm using underscorejs library, i need to see if underscorejs exists in the parent site and if so what version.

If underscore is already defined in the site and if the version matches with the one i used. I would inturn use their own defined underscore and not make a CDN call to load underscorejs for my widget.

Share Improve this question asked Nov 5, 2014 at 13:53 Ashwath GovindAshwath Govind 531 silver badge4 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 6

You can easily check that with the following

if (!window._ || window._.VERSION !== '1.7.0') {
  // Load underscore from CDN
}

Get the version of underscorejs used

Check the library itself. Most likely it retained the copyright ment on top of the file.

i need to see if underscorejs exists in the parent site

_.VERSION

You can use this pattern to load library from HTML:

<script>
    (window._ && window._.VERSION === '1.7.0') || document.write("<script src='//cdnjs.cloudflare./ajax/libs/underscore.js/1.7.0/underscore-min.js'>\x3C/script>");
</script>

You can put this script at the beginning to the widget HTML.

发布评论

评论列表(0)

  1. 暂无评论