dart-archive / polymer-dart

Polymer support for Dart
https://pub.dartlang.org/packages/polymer
BSD 3-Clause "New" or "Revised" License
180 stars 33 forks source link

Polymer documentation should state reason and implication of placing <script> elements in <head> #106

Closed DartBot closed 9 years ago

DartBot commented 9 years ago

Originally opened as dart-lang/sdk#15980

This issue was originally filed by yu.as...@gmail.com


URL (if available): Some of https://www.dartlang.org/polymer-dart/ https://www.dartlang.org/docs/tutorials/polymer-intro/ https://api.dartlang.org/docs/channels/stable/latest/polymer.html

Issue/feedback: The first example on <https://www.dartlang.org/polymer-dart/&gt; places <script> elements in <head>. The same holds for the sample code on <https://www.dartlang.org/docs/tutorials/polymer-intro/&gt; and the the sample code generated by Dart Editor when the user selects “Web application (using the polymer library)”.

I assume that there is a reason the sample codes using Polymer.dart tend to place <script> tags on top, such as to avoid the flash of unstyled content in some cases. However, this means that the Dart code and the compiled JavaScript code are executed at different timing. I was not the only one who was confused by this discrepancy (see issue dart-lang/sdk#15125).

I think that the reason for putting <script> elements on top (assuming there is a reason) and implication of doing so (Dart and JavaScript behave differently) should be stated somewhere in the documentation of Polymer.dart.

(Needless to say, if there is no reason to put <script> elements on top, then the codes should be modified. Note that the page “Embedding Dart in HTML” <https://www.dartlang.org/articles/embedding-in-html/#dart-html-semantics&gt; recommends to place <script> elements at the end of a document, seemingly to avoid this very discrepancy.)

DartBot commented 9 years ago

Comment by kwalrath


Siggi, could you take a first crack at defining what our policy and reasoning are?


Set owner to @sigmundch. Added Library-Polymer, Docs-API, Docs-Tutorials labels.

DartBot commented 9 years ago

This comment was originally written by yu.asaku...@gmail.com


Also related: issue dart-lang/sdk#15229.

DartBot commented 9 years ago

Comment by sigmundch


These are great points, @­yu.asakusa thanks for filing this bug.

I'm cc'ing a few others to confirm.

Because of today's timing of Dart script tags in Dartium (Dartium launches code at dom-content-loaded), we should state our policy like we did in the 'embedding-in-html' article: put it at the end to keep the behavior consistent after compiling with dart2js. And, as you suggest, the examples should be modified to put the script tag at the end.

We have design ideas to eventually support sync execution of Dart script tags, but it's not going to be available for a while. When we reach that point we'll probably revisit the policy.


cc @jmesserly. cc @blois. cc @vsmenon.

DartBot commented 9 years ago

Comment by blois


To best approximate Dartium behavior, the dart2js script should have a defer attribute. If you do this, then it can be anywhere in the file (head included).

Related is https://code.google.com/p/dart/issues/detail?id=15229.

DartBot commented 9 years ago

Comment by kwalrath


cc @sethladd.

DartBot commented 9 years ago

Comment by sethladd


Pete, good point. Our skeleton app from Dart Editor should add defer. I've CC'ed Keerti.


cc @keertip.

DartBot commented 9 years ago

Comment by sigmundch


Removed the owner.

DartBot commented 9 years ago

Comment by jmesserly


Removed Area-Documentation label. Added area-pkg, Pkg-Polymer labels.

DartBot commented 9 years ago

Comment by jmesserly


Removed Library-Polymer label.

DartBot commented 9 years ago

Comment by kwalrath


Removed Type-Defect label. Added Type-Documentation label.

DartBot commented 9 years ago

Comment by sigmundch


Removed area-pkg label. Added Area-Site label.

DartBot commented 9 years ago

Comment by nicolasgarnier


This issue has been moved to Github as part of a migration. Please use the Issue on Github going forward: https://github.com/dart-lang/dartlang.org/issues


Added MovedToGithub label.