Remove unused code of external JavaScript file?

已查看 128 次
跳至第一个未读帖子

confile

未读,
2015年12月30日 17:11:172015/12/30
收件人 GWT Contributors
I have an external JavaScript file which I use using JSNI or JS Interop. 

I only use parts of this js file/ library. 

Is it possible to reduce the code of this external js file using GWT?

Colin Alworth

未读,
2015年12月30日 19:17:442015/12/30
收件人 google-web-tool...@googlegroups.com
It depends on how you are including the JavaScript source. 

If it is a <script> tag in the .gwt.xml or the html host page, the GWT compiler barely knows it exists, and will do nothing with it. Likewise, if you use the ScriptInjector to make it available to the app, either from a url, or from a String or External/TextResource - as far as GWT can tell, its just a String.

If on the other hand you put it into a JSNI method, the compiler will understand that it is source and should be optimized as much as possible. Note however that JSNI is limited in how it can be optimized, though enabling the Closure compiler can often do a more comprehensive job of cleaning up that JS source, though this cleanup may in some cases break code that isn't prepared to be optimized in that way.

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/4b0d67b6-ba5c-42d9-a5ff-894f7eccd752%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

confile

未读,
2015年12月31日 05:38:222015/12/31
收件人 GWT Contributors
Okay, When I put the code of the external JS file in a JSNI method. Do I have to put all the code I one method? To have a concrete example here is the code I use: 


Could you please give an example of how you would do it in this case?


Am Donnerstag, 31. Dezember 2015 01:17:44 UTC+1 schrieb Colin Alworth:
It depends on how you are including the JavaScript source. 

If it is a <script> tag in the .gwt.xml or the html host page, the GWT compiler barely knows it exists, and will do nothing with it. Likewise, if you use the ScriptInjector to make it available to the app, either from a url, or from a String or External/TextResource - as far as GWT can tell, its just a String.

If on the other hand you put it into a JSNI method, the compiler will understand that it is source and should be optimized as much as possible. Note however that JSNI is limited in how it can be optimized, though enabling the Closure compiler can often do a more comprehensive job of cleaning up that JS source, though this cleanup may in some cases break code that isn't prepared to be optimized in that way.

On Wed, Dec 30, 2015 at 4:11 PM confile <michael....@googlemail.com> wrote:
I have an external JavaScript file which I use using JSNI or JS Interop. 

I only use parts of this js file/ library. 

Is it possible to reduce the code of this external js file using GWT?

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-contributors+unsubscribe@googlegroups.com.

Colin Alworth

未读,
2015年12月31日 10:02:472015/12/31
收件人 GWT Contributors
The short answer is yes, it can all go into one method, or several methods, etc. The important part is "what does that JS expect to do", and how might we accidentally break it by letting a compiler at it. 

With that big of a file, I'm afraid I don't have time right now to take it apart piece by piece and see what might break. Also, this is really the wrong venue for a question not about contributing to GWT - I suggest continuing on the regular GWT mailing list, a stackoverflow post, or in gitter.im/project/gwt or in the ##gwt channel in freenode.

On Thu, Dec 31, 2015 at 4:38 AM confile <michael....@googlemail.com> wrote:
Okay, When I put the code of the external JS file in a JSNI method. Do I have to put all the code I one method? To have a concrete example here is the code I use: 


Could you please give an example of how you would do it in this case?


Am Donnerstag, 31. Dezember 2015 01:17:44 UTC+1 schrieb Colin Alworth:
It depends on how you are including the JavaScript source. 

If it is a <script> tag in the .gwt.xml or the html host page, the GWT compiler barely knows it exists, and will do nothing with it. Likewise, if you use the ScriptInjector to make it available to the app, either from a url, or from a String or External/TextResource - as far as GWT can tell, its just a String.

If on the other hand you put it into a JSNI method, the compiler will understand that it is source and should be optimized as much as possible. Note however that JSNI is limited in how it can be optimized, though enabling the Closure compiler can often do a more comprehensive job of cleaning up that JS source, though this cleanup may in some cases break code that isn't prepared to be optimized in that way.

On Wed, Dec 30, 2015 at 4:11 PM confile <michael....@googlemail.com> wrote:
I have an external JavaScript file which I use using JSNI or JS Interop. 

I only use parts of this js file/ library. 

Is it possible to reduce the code of this external js file using GWT?

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/fcb0b0e1-fd98-48d8-bef4-8d63ce47af4d%40googlegroups.com.

Jens

未读,
2015年12月31日 11:06:272015/12/31
收件人 GWT Contributors
I think Ray Cromwell did something like that using a generator and a linker. Can't remember exact details and he never shared is experiment. I would guess it was a resource generator so you can define a JavaScriptResource in ClientBundle (instead of TextResource) and then this resource made its way to closure compiler as a real JS artifact so it can be optimized.

I guess this use case will be a lot easier with J2CL in the future.

-- J.
回复全部
回复作者
转发
0 个新帖子