简体   繁体   English

第三方像素,无错误或延迟

[英]3rd party pixel without error or delays

I have a database of 3rd party tracking pixels that I add to my own output to either inform that third party of an event or let them set their cookie. 我有一个第三方跟踪像素的数据库,我将其添加到自己的输出中以通知第三方事件或让他们设置其Cookie。 Easiest to handle are image pixels - you just set up <img src="..."> and everything just works. 最容易处理的是图像像素-您只需设置<img src="..."> ,一切就可以正常进行。 However, some pixels in database are of script type - ie 3rd party server returns empty string and Content-Type as text/javascript . 但是,数据库中的某些像素属于script类型-即,第三方服务器返回空字符串,而Content-Type作为text/javascript

So far I thought of following approaches: 到目前为止,我想到了以下方法:

  1. Just insert them in same img . 只需将它们插入相同的img Request will succeed, but there will be warning on console and some users just don't like that 请求将成功,但是控制台上将出现警告,并且某些用户不喜欢这样
  2. Give those pixels proper <script> tag while writing it with document.write - depending on browser, slow response of 3rd party server might cause entire page to halt, and that is also very bad. 在使用document.write进行写操作时,给这些像素适当的<script>标签-根据浏览器的不同,第三方服务器的响应缓慢可能会导致整个页面停止运行,这也非常糟糕。
  3. Dynamically generate DOM script element with necessary src and append it somewhere in head . 动态生成具有必要src DOM script元素,并将其附加在head Seems to work, but I didn't test extensively yet and not sure if there's any hidden problems I'm missing. 似乎可以工作,但是我还没有进行广泛的测试,也不确定我是否缺少任何隐藏的问题。

So, is there some generally accepted method to include such pixels in a way that would guarantee no errors in console or halts on slow 3rd party server response? 那么,是否存在某种普遍接受的方法来包含此类像素,从而可以确保不会出现控制台错误或因第三方服务器响应缓慢而暂停? (additional points if it can handle some other arbitrary content type, not just text/javascript ). (如果它可以处理其他任意内容类型,而不仅仅是text/javascript ,则为附加点)。

There's an async attribute which IE ignores, yet makes your scripts load asynchronously in other browsers, thereby not blocking site download. IE会忽略一个异步属性,但会使您的脚本在其他浏览器中异步加载,从而不会阻止站点下载。

http://davidwalsh.name/html5-async http://davidwalsh.name/html5-async

On how to insert it well (and perhaps that also works in IE, look at comments): https://plus.google.com/116910304844117268718/posts/TripyAFKMof 有关如何将其正确插入的方法(也许在IE中也可以使用,请查看评论): https : //plus.google.com/116910304844117268718/posts/TripyAFKMof

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解析Foursquare JSON,无需第三方 - parse foursquare json without 3rd party 如何将变量动态传递给第三方跟踪像素 - How to dynamically pass a variable to a 3rd party tracking pixel 查询具有数组的对象(没有第三方脚本) - Query objects with an array (without 3rd party script) 无需第三方扩展程序即可永久地在Google Chrome浏览器中执行用户脚本 - Executing Userscripts in Google Chrome permanentely without 3rd party Extension 按模式查找ID(无jquery或3rd party库) - Find id by pattern (Without jquery or 3rd party libraries) 如何在不安装npm的情况下包含第三方npm模块? - How to include 3rd party npm module without npm install? 在没有任何第三方库的情况下将Highcharts与Angular5集成 - Integrate Highcharts with Angular5 without any 3rd Party library 在第三方SDK意图上调用startActivityForResult时出错 - Error calling startActivityForResult on 3rd party SDK intent 第三方反应模块(执行器)的Webpack错误 - Webpack error for 3rd party react module (effector) javascript将自定义错误处理程序设置为第三方插件或模块 - javascript setting custom error handler to 3rd party plugins or modules
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM