RobinvdA
RobinvdA

Reputation: 1363

Performance of website with multiple files

I'm developing a website where you can order a product. This product has a lot of options etc so the user has to go through 10 steps to complete his/her order.

At the moment i have 1 file (index.php) which handles all steps. The code is a mess and the file is getting pretty big. I thought maybe splitting everything up in seperate files would be better. However, i don't want the user to reload the page at every step.

My first thoughts were PHP's file_get_contents() or using Ajax to load every file. But i don't know what method achieves the best performance? Or maybe you have an alternative?

Upvotes: 0

Views: 103

Answers (2)

Alex W
Alex W

Reputation: 38243

If the pages are just a bunch of forms/options, you could use jQuery/JavaScript to AJAX them in. And each time the user advances to another step, you could save the data into a cookie. Then at the end of all of the steps, submit all of the data at a single time to PHP. That would make your PHP code less scattered and would offload most of the processing work, for the individual steps, to the client's browser, which would reduce the server load caused by PHP processing each individual step (for all users buying your product).

You could store each form's HTML in separate HTML files on the server, or you could echo the HTML for a given step, from your PHP script based on a $_GET['step'] value, etc.

Instead of hiding/displaying your divs with jQuery, this method would actually replace the HTML for a given step with the next/previous step's HTML.

Using PHP's include function is not going to improve performance because it acts the same as if the code of the included file was in place of the include directive, however it requires PHP to have some additional overhead because it has to load and evaluate the specified file.

Upvotes: 1

prcvcc
prcvcc

Reputation: 2230

keep 1 file, make a class and each step is a method of said class, you then invoke the right method upon reloading it via ajax. if you create several files it will be even messier.

Upvotes: 3

Related Questions