0

I would like all the following requests to reach the same static file hosted on Amazon S3, for example:

http://cloudfront.net/js/12345.js
http://cloudfront.net/js/54232.js
http://cloudfront.net/js/76543.js

would all point to a single static file on Amazon S3 such as:

/js/real-file.js

then the javascript code in this real file would be able to get the numbers from the request using something like the following found here:

var scripts = document.getElementsByTagName('script');
var scriptName = scripts[scripts.length-1].src;

I know this would be possible using a query parameter such as:

/js/real-file.js?a=12345

but I would like to know if it's possible to achieve without it.

If not on Amazon, then perhaps using a different CDN service?

Community
  • 1
  • 1
matthew
  • 2,156
  • 5
  • 22
  • 38

1 Answers1

1

The following answer solved this for me: answer-35354677

The solution is:

  1. Make sure you have the index route configured for your website. Mostly it is index.html
  2. Remove routing rules from S3 configurations
  3. Put a Cloudfront in front of your S3 bucket.
  4. Configure error page rules for your Cloudfront instance. In the error rules specify:
    • Http error code: 404 (and 403 or other errors as per need)
    • Error Caching Minimum TTL (seconds) : 0
    • Customize response: Yes
    • Response Page Path : /index.html
    • HTTP Response Code: 200
Community
  • 1
  • 1
matthew
  • 2,156
  • 5
  • 22
  • 38