I need to upload to an Amazon S3 bucket a website that has over 50 pages, and on each of them there is a navigation bar at the top that is inserted using php. But Amazon S3 bucket does not support php and I need to re-do the navigation bar with just Javascript.
I made dropdown menus with Javascript that work fine on a single page.
But I would like to have a single file containing the dropdown menus, that is inserted in all the 50 pages, so that if I need to edit something I do it only once instead of 50 times.
I know how to insert some content in multiple pages using Javascript (I have used one of the answers to this post )
But this does not work if the content I insert is html code that is used to produce the dropdown menus that work with Javascript.
So my question is, is there a way to do such a thing with only Javascript, so that it will work on the Amazon S3 bucket?
2
Answers
If you can’t use PHP on S3 and you MUST put the website there, then a front-end framework like React might be the way to go. Make the navigation menu a React component, then it becomes easy to include it on every page. Otherwise, put the website somewhere else.
Let’s say you’ve added the same script to every HTML file in your bucket:
Now, in this custom JS file, you can add the following:
Using the above, you can insert your dropdown menu using whatever method you choose.