-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change boilerplate bootstrap <style> to <script> #323
Comments
Looks good. Here's what I proposed in #548...
@dvoytenko's script looks a lot more robust than my simple suggestion (with the addition of the onerror handler). In any case, I'm really, really glad to see the opacity reset being moved out of style and into script. And being able to drop the proprietary amp-custom attribute is definitely a bonus! |
+1 fallback for nonjs or failed js rendering should be part of it, what if the js errors and the body never gets displayed... |
/cc @Gregable @powdercloud this is coming down the pike. |
The primary problem with this is that it does not work with our default CSP. We cannot use nonces in AMP because they are not compatible with cache-control: public (besides not being supported in Safari). We could use a hash, but that would very complicated (Maybe OK) but also turn on unsafe-inline in Safari which is an absolute no-go. So, while I absolutely love the suggestions here I think we cannot implement them until Safari ships a robust CSP implementation. One of our goal in AMP is robust naive serving. Making every single publisher on the planet support a complex dynamic CSP seems very unlikely to be successful. Does anyone have an idea that works without any inline JS? |
Yeah, I haven't thought about CSP. It's definitely a bit of a show stopper. But perhaps we can still make our current boilerplate simpler and more reliable? Among other things:
|
I think with the css parser getting ready it should be ok to have the opacity thing inside the same style tag as what's now known as the amp-custom style. We need to play a little bit with this to get a feel for how to implement rules for the css though. |
@dvoytenko those are all good suggestions, but they don't address the big win which would be to be robust in the case of JS load failure. |
@cramforce Yes, unfortunately. But it looks like we don't have much of an option at this time? If we can't inline style and can't do nonce do we have any other option? One version would have |
Is there some way to listen to the script element that's loading amp.js, like there is with onreadystatechange with xml http requests? |
Well, if we can insert inline script - we can do it all with ease as described above. The problem is that our CSP doesn't allow inline styles and things are even more complicated when Safari is involved. |
Abusing a CSS animation is out as well for it, yes? |
@powdercloud I think that is an amazing idea!!! An opacity animation that stays at 0 for N seconds that then goes to 1. |
@powdercloud @cramforce Ooh, that's smart! My main concern with the current situation is that mixes JavaScript and CSS, assuming both will work in tandem. A solution that's either all JavaScript or all CSS would be much more robust. Until now, I had really only been thinking of the JavaScript options, but what you're proposing (all CSS) sounds much more straightforward and elegant. |
@powdercloud hah, that would be a really neat sol'n. |
Yeah, I think it's a cool idea. We can try that. It could look something like this: body {
opacity: 0;
animation: amp-starter 0s 10s 1 normal forwards;
}
@keyframes amp-starter {
0% { opacity: 0; }
100% { opacity: 1; }
} We can give it a max of, say, 10 seconds to wait before the opacity is reset to 1 automatically. We'd still need a JS solution that would reset body at the earliest opportunity to body {
opacity: 1;
animation: none;
} The benefit here is, of course, that opacity can be reset to 1 if JS fails to load/initialize for any reason. On the other hand we need to consider:
|
I think a good timeout value would be 3-4 seconds, very similar to Chrome's default timeout for fonts. |
@dvoytenko wrote:
Would it possible to drop the initial I don't the think the lack of the initial
|
Ok. I think boilerplate will look like this then: <style>body{opacity:0;-webkit-animation:-amp-start 0s 10s 1 normal forwards;-moz-animation:-amp-start 0s 10s 1 normal forwards;-ms-animation:-amp-start 0s 10s 1 normal forwards;animation:-amp-start 0s 10s 1 normal forwards}@-webkit-keyframes -amp-start{0%{opacity:0}to{opacity:1}}@-moz-keyframes -amp-start{0%{opacity:0}to{opacity:1}}@-ms-keyframes -amp-start{0%{opacity:0}to{opacity:1}}@keyframes -amp-start{0%{opacity:0}to{opacity:1}}</style>
<noscript><style>body{opacity:1;-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> It looks like we actually can drop some of prefixes but we'll probably have to keep A version without opacity: <style>body{-webkit-animation:-amp-start 0s 10s 1 normal forwards;-moz-animation:-amp-start 0s 10s 1 normal forwards;-ms-animation:-amp-start 0s 10s 1 normal forwards;animation:-amp-start 0s 10s 1 normal forwards}@-webkit-keyframes -amp-start{0%{opacity:0}to{opacity:1}}@-moz-keyframes -amp-start{0%{opacity:0}to{opacity:1}}@-ms-keyframes -amp-start{0%{opacity:0}to{opacity:1}}@keyframes -amp-start{0%{opacity:0}to{opacity:1}}</style>
<noscript><style>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> This version assumes that zero-offset state in |
@dvoytenko See @adactio's idea that would probably allow being a bit more aggressive on the non-prefix side. |
@adactio, dropping initial opacity works fine on devices I checked. The animation would have to change to start immediately (currently delayed 10s above) and would run instead for that duration and would need to use a step-end timing function or similar. I haven't yet found a clear confirmation that the keyframes animation MUST start before the first paint - so that needs to still be confirmed. |
But I think it's reasonable to expect that zero-offset step is applied immediately. So, I think this should work well. |
@dvoytenko you have opacity 0 in noscript in #323 (comment) which is worse than opacity 1 currently; I thought the point was to avoid the noscript distinction entirely |
@kevinmarks Typo. Fixed. I also added a no-opacity version. |
@dvoytenko Thanks for testing the version with initial opacity: much appreciated. |
Closing this assuming #998 covers it and necessary validator changes have happened. Reopen if still needed. |
@sriramkrish85, @cramforce: I believe this can be closed now? |
The docs are still out of date: https://www.ampproject.org/docs/get_started/create/basic_markup.html Can we re-open this until the docs are updated? |
@adactio Thank you I filed ampproject/amp.dev#32. |
Next docs push will fix. Should happen any day. On Fri, Feb 5, 2016 at 1:23 PM, Johannes Henkel notifications@github.com
|
confirming with @Meggin if we can do a release |
Need to make a few changes to validation doc. Can you give me an hour?
|
docs pages should be updated w/in the hour |
Milestone: Post Preview
The script is:
And the counterpart in AMP runtime:
2.1. The file will be compiled, minified and obfuscated
2.2. The script will be integrated into validator. Validator will validate against all known versions of this script.
2.3. Once validator is updated, it will be posted in the "Setup" publishers' guide.
<style>
element. We will go back to require a single<style>
in the document.The text was updated successfully, but these errors were encountered: