[英]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: 到目前为止,我想到了以下方法:
img
. 只需将它们插入相同的img
。 Request will succeed, but there will be warning on console and some users just don't like that 请求将成功,但是控制台上将出现警告,并且某些用户不喜欢这样 <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>
标签-根据浏览器的不同,第三方服务器的响应缓慢可能会导致整个页面停止运行,这也非常糟糕。 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.