I acquainted a client who designed his own fashion magazine site. My company handed the project to me to make it with WordPress. When I was making the complete template for the site, I found his complete thought: and it's completely eerie for me; because the design for the home page had many more blocks, not less than 20 blocks, and each of the blocks demands a new
WP_Query() (and just now from this thread I was known that I's right making new
WP_Query() for each of the blocks).
And the final product was damn slow - as I suspected.
I'm not a WordPress master, so as I understood
WP_Query() is whenever it's called, it hits the db with it's query and retrieve the data as per the query. So in this site, in the Home Page it's hitting 20 times and then retrieving the data and that makes it slower.
With this scenario, I's thinking of some Speeding Up solutions, like:
- Separating the loop for each of the posts with a common function so that it loads a single time with different parameters each of the time
- Some basic CSS things to speed up the layout
- Separating the common things into different files and include them with
get_template_part(), so that the common thing will load a single time and echo multiple times wherever it's necessary
- Using LazyLoad to the site images to let 'em not hamper the site speed when the content and layout is important first
- Caching the site's content
- WP Smush.it the images
- If possible and doesn't create conflict then using the .js compression
With these thoughts, I may be wrong with much of their concepts, but I found them logically good.
So the ultimate questions are:
- What can be done further to speed up a site with multiple queries (i.e. 20 different queries)?
- Or, is there any better solution instead of using
WP_Query()for each of the queries?