FR: Variable subs on page load for dynamic local content
Often time, important info are passed over in urls and used displaying messages on the page. For example, www.example.com?location=Washington%20DC and <p [text]='Welcome to QUERY_PARAM(location')>Where are you...
Right now var substitutions only happens in the src or href attributes and it won't happen until on click.
Ideal feature: all vars can be made available using the substitution MACROs anytime anywhere or a parallel predefined API in AMP_STATE.
Triaging to @choumx , Feel free to re-assign 😄
Adding additional context. This feature request initiated from one of the partners we are working with. Our team (MSC) is interested in contributing to the development of the feature.
Would love to get your thoughts on best implementation method. Would it be a component or deeper framework level change?
Would be helpful to see some concrete use cases for context. E.g. why is substitution-on-click insufficient?
I will share two use cases.
-
Imagine national distributors such as car parts distributor or phone equipment distributor. They serve customers who are accustomed to buying products over the phone. And the distributor has over a hundred 1-800 numbers. They have one landing page to show different 1-800 numbers. They pass the phone number as a URL parameter. The phone number is then extracted from the url and displayed as a heading on the page. With this setup, they only need one page, not 100. AMP doesn't have this feature.
-
Imagine an online retailer who has thousands of coupon codes for discount. The coupon code is included in the url and then displayed on the page. With normal html, they can just extract the url parameter and display the coupon code by the product. This is not possible in AMP.
Does that help? If there are elegant workarounds to address above use cases, I'd love to learn them.
A partial workaround you could try today is using a hash anchor link to direct the user to the specific item by id attribute. The other items will still be visible, though at thousands of items per page it's probably a good idea to divide them into several pages by category.
AMP by design tries to avoid client-side rendering since it can unnecessarily delay "first meaningful paint". That said, one potential way to implement this is by allowing variable substitutions in #15647.
/cc @aghassemi @nainar
I think allowing initial use of amp-state won't solve these use cases which specific params are supplied via the urls such as ad campaigns and, in the future, amp-to-amp navigations. While client-side rendering can delay FMP (marginally), a server-side round-trip fetch something as trivial as a random number would be many times worse.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.