问题
I am converting a page to google AMP and need to access cookies to set a view of a division. I am thinking of creating an API for this.
The API will just return all the cookies available on my domain in JSON format. I will hit the API using <amp-state>
component and store the returned JSON. Then will take actions according to this state.
Is this a valid approach to use in AMP? Is there any security flow in this?
回答1:
Using amp-list is the right approach in this case. amp-list makes a request to your server, which can read the cookie and return an appropriate JSON response. You can render then the form / button inside the amp-list using amp-mustache.
This samples demonstrates how to do this: https://ampbyexample.com/advanced/favorite_button/.
来源:https://stackoverflow.com/questions/48022696/access-cookies-through-an-api-on-amp-page