未加星标

Agent as a Module

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二05 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

We recently released a new version of the TrackJS agent as a javascript module. This change was often-requested and long-overdue. It will make it way easier for you to include TrackJS in your applications and bundle it with your assets.

Loading the Agent

TrackJS Agent 3.0.0 is a major-version update that supports loading as an ES6 Module , CommonJS , or AMD in addition to the classic global namespace. This enables you to easily load us with webpack, browserify, or other build system.

import { TrackJS } from 'trackjs'; TrackJS.install({ token: 'YOUR_TOKEN' }); TrackJS.track('oh no! something went wrong!');

Example Loading TrackJS as an ES6 Module

We strongly recommend bundling the agent into your web application via npm , or by downloading a known version for high-performance production systems. Bundling reduces the total number of network requests, and potential for problems accessing our CDN from browser plugins or proxies.

Our CDN still works great, and is the easiest way to get started. We took the opportunity with this major release to change our URL patterns. We stopped using the term tracker to refer to our agent as it incorrectly got caught up in overly-broad privacy-blockers.

<script src="https://cdn.trackjs.com/agent/v3/latest/t.js"></script> <script> TrackJS.install({ token: 'YOUR_TOKEN' }); TrackJS.track('oh no! something went wrong!'); </script>

Example Loading TrackJS from the CDN

We automatically push the latest stable release of the agent to https://cdn.trackjs.com/agent/v3/latest/t.js . We added the major version to the URL as v3 , because we don’t want people to automatically load changes that may break functionality. If you are using the previous URL, https://cdn.trackjs.com/releases/current/tracker.js , you will not get the v3 agent. “Current” is through the 2.X line only.

You can also access a specific version of our agent on the CDN using the versioned paths: https://cdn.trackjs.com/agent/3.0.0/t.js . This gives you control of when to accept changes to the agent, without having to self-host the file.

Using the Agent

The agent behaves as a singleton, reflecting that it can only be installed into the document once. Keeping with community naming norms for singletons, we changed the namespace from trackJs to TrackJS , which also supports ourupdated brand.

The previous agent relied on a global configuration object to install itself immediately. This had a number of advantages, but it was not always obvious to the developer and lacked explicitness. The new agent introduces a install(opts) command to explicitly control when the agent adds its listeners to the document.

install(opts) allows the agent configuration to be placed in more obvious parts of your application. However, you must understand that telemetry and error reporting will not start until the agent is installed. By delaying the call to install(opts) , you may be blind to errors that occur earlier in initialization or bootstrapping of your application.

Backwards Compatibility

We remain committed to backwards compatibility. Agent 3.0.0 is fully backwards compatible with the names and API of Agent 2.X and 1.X. If you liked using trackJs as the global namespace, it’s still there. If you liked auto-initialization with window._trackJs , that still works too.

We’re bucking the trend and trying to build web software that lasts. We prioritize backwards compatibility in our software, our APIs, and our agents to make using our tools as easy as possible for you.

Grab the new agent, and let us know what you think. Our development priorities are driven by you: our customers. If you don’t use TrackJS, that’s easy to fix. Grab a free 30 day trial and let us help you fix JavaScript bugs and build better webapps.

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

代码区博客精选文章
分页:12
转载请注明
本文标题:Agent as a Module
本站链接:https://www.codesec.net/view/611296.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(70)