Access cookies through an API on AMP page

故事扮演 提交于 2019-12-03 14:05:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!