简体   繁体   English

GWT浏览器敏感代码

[英]GWT browser sensitive code

In gwtproject it says if you use browser-sensitive code, then you must use user.agent set property. 在gwtproject中,它表示如果使用浏览器敏感代码,则必须使用user.agent set属性。 So what is browser-sensitive code exactly? 那么到底什么是浏览器敏感代码?

browser-sensitive code means a piece of code which is different for each browser implementation. browser-sensitive code是指一段代码,对于每个浏览器实现来说都是不同的。

In GWT you can mark these pieces of code, and make that only the appropriate portion of code per each browser is included in its permutation, making the compiled code smaller (not including unnecessary code) and faster (not having to evaluate browser conditions) 在GWT中,您可以标记这些代码段,并使其每个排列的浏览器仅包含适当的代码部分,从而使编译后的代码更小(不包括不必要的代码)且速度更快(不必评估浏览器条件)

In traditional javascript libraries like jQuery, they have their code plenty of blocks like: 在像jQuery这样的传统javascript库中,它们的代码有很多块,例如:

 if (jquery.browser.isie) {
   // lines to be executed only in IE
 } else {
   // lines to be executed only in non IE
 }

As you see, these libraries include the code for all browsers, even though each browser executes just its specific block. 如您所见,即使每个浏览器仅执行其特定的块,这些库也包含所有浏览器的代码。

Note that the way GWT has for doing it is using a technique called deferred-binding . 请注意,GWT执行此操作的方法是使用一种称为deferred-binding的技术。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM