简体   繁体   中英

How can I get my HTML file to access my CSS and JavaScript files in an Amazon S3 Bucket?

I am currently trying to host an html file as a website on AWS S3 to get around the CORS Policy. When I put all of my documents into a new bucket, the html file opens without accessing the css or javascript that is in the bucket with it. When I open the file outside of the bucket (ie from my computer). The page opens with all the css and javascript working. I am wondering how I can get my css and javascript working within the bucket.

There are a few ideas I have that might help with the problem, but I have no idea how to implement them. I'm not sure if there are extra permissions I must grant to my files to allow them to access each other. I'm also not sure if there is something within the code of the html file that must change. Any help is much appreciated!

You can use static webhosting for a s3 bucket see [1].

Otherwise it is just a data container, where you load a file form and Context with referenced files is not matched to the bucket + path directly - I guess.

I unfortunately don't have better explanation at the moment.

Alternatively if the files are publicly available you could maybe also provide the full paths to the files in the bucket within the html.

But that is not very nice or maintainable (if it even works).

[1] https://docs.aws.amazon.com/en_en/AmazonS3/latest/user-guide/static-website-hosting.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM