I see sometimes CORS errors while loading map using Layer.fromPortalItem({}).
I notice "X:Cache Errors from cloudfront" in the request headers.
Since this is not always reproducible, I wonder if the CORS errors are due to this reason. Is there any other area I need to look at? Or is there any configurations to avoid CORS errors while loading map using ArcGIS Online item Id?
Verifying the information the "X:Cache Errors from cloudfront" in the request headers. It was resolved in another post. You will have to verify some items whether origin caching headers conflict with your distribution's custom object caching, verify these steps according with the issues that you have it.
< HTTP/1.1 200 OK< Content-Type: text/html
< Content-Length: 437
< Connection: keep-alive
< Date: Sat, 03 Feb 2018 19:26:45 GMT
< Last-Modified: Sat, 03 Feb 2018 19:25:24 GMT
< ETag: "example12345abcdefghijklmno54321"
< Cache-Control: max-age=300, Public
< Accept-Ranges: bytes
< Server: AmazonS3
< Age: 14
< X-Cache: Hit from cloudfront
< HTTP/1.1 200 OK< Content-Type: text/html
< Content-Length: 437
< Connection: keep-alive
< Date: Sat, 03 Feb 2018 19:26:45 GMT
< Last-Modified: Sat, 03 Feb 2018 19:25:24 GMT
< ETag: "example12345abcdefghijklmno54321"
< Cache-Control: no-cache, no-store
< Accept-Ranges: bytes
< Server: AmazonS3
< X-Cache: Miss from cloudfront
There is this article that may be of help: https://repost.aws/knowledge-center/cloudfront-custom-object-caching.
Regards,
Tatiana