@tripcloud/ares-agent

Ares API used in business applications.

Usage no npm install needed!

<script type="module">
  import tripcloudAresAgent from 'https://cdn.skypack.dev/@tripcloud/ares-agent';
</script>

README

@tripcloud/ares-agent

ARES 静态资源应用程序接口(服务端)

ctrip npm version

从 0.1.0 版本开始,@ctrip/ares-agent 支持两种不同的模式。

域名自适应模式

如需了解该模式下的使用方法,请阅读《ARES 用户手册》相关篇章:Node.js SDK For ARES.i18n Modules

传统模式

传统模式下,所引用的静态资源所属站点(域名)是明确的。

const ares = require('@ctrip/ares-agent/normal');

// 获取附加了内容摘要信息的静态资源 URL,以帮助规避缓存陷阱。
let urlname = '//webresource.english.c-ctrip.com/ARES/locale/zh_CN.js';
let realurl = ares.getRealUrl(urlname));

// 生成全新的 URL,该地址的响应实体为指定资源依顺序合并后的结果。
let concatUrl = ares.getConcatUrl({
    protocol: 'https:', 
    hostname: 'webresource.english.c-ctrip.com',
    pathnames: [ '/ARES/locale/zh_CN.js', 'en_US.js' ],
});

getRealUrl()

获取附加了内容摘要信息的静态资源 URL,以帮助规避缓存陷阱。

调用方式:

  • string getRealUrl(string urlname)

参数说明:

  • urlname string
    参数应当是一个完整的 URL。
    协议头可以省略,此时 urlname// 开头。
    参数不应附带 querystring 或 hash,否则函数将原状返回该参数。

返回的 URL 的协议头与参数地址的协议头保持一致,如参数地址不含协议头,则返回值同样省略协议头。

getConcatUrl()

生成全新的 URL,该地址的响应实体为指定资源依顺序合并后的结果。

调用方式:

  • string getConcatUrl(string options)

参数说明:

  • options.protocol string OPTIONAL
    此选项可以省略,此时返回的 URL 不含协议头,以 // 开头。

  • options.hostname string
    只支持对同一域下的静态资源进行合并,故 hostname 只有一个。

  • options.pathnames string[]
    待合并的静态资源的路径,可以使用相对路径。