Published on April 7, 2022 •
Updated on June 13, 2024
Today, we will create an SPA with PHP. Our output will look like this. (Ignore the speed of the GIF, compressing it made it look slower than it is somehow)
Now create those files. Then, we’ll make the header and footer templates.
header.php
footer.php
Now put that code in the correct PHP files (header.php, footer.php)
After that, we will make our utils in utils.php.
The first function is a utility for showing the title and adding styles.
Then we create another function to show the footer and require the javascript files.
Now, we add these two functions to utils.php.
Adding some pages
Now we add some pages so we can test our SPA.
index.php
about.php
Now let’s see what we’ve got!
Now we’ll add our SPA functionality. We will use the Instantclick library for this. Just download this file and replace the instantclick.min.js file in our project!
That’s all you need to do. You now have created an SPA with PHP.