0

My homepage (index.php) is generated dynamicly by PHP, so it takes about 1s till the the page is delivered to the user.

Because my css and js script is in the header of (index.php), after this 1s the css and js will start to download.

Is there some general way of preloading this js and css files?


My aproach would be to delete all content of index.php, include just <'head> with my css and js file, and then do some js to load the whole indexOriginal.php (with the dynamic content generated on my server by PHP), so this should enable the user to download the css, js in parallel of indexOriginal.php.

Is this the right aproach?

1
  • you can try having php output and flush the page headers before it gets busy building the page's body. Commented Aug 9, 2013 at 16:41

3 Answers 3

1

The approach you suggested could work. You also might consider altering your PHP script to hurriedly deliver the first part of the page (<html> down through <body>) before it starts getting the rest of the page together (see http://php.net/manual/en/function.flush.php).

Sign up to request clarification or add additional context in comments.

Comments

1

Your page full generated by backend and sended to user only after php script end its work.

You could, for example, create page like.

<html><head><script></script></head><body></body></html>

In <script></script> load, for example, JQuery and do something like

$(document).ready($('body').load('/path/to/your/script.php'))

But I really thing this wouldn't be a good practice. Also I don't think that Google would parse your site content with this solution.

I think you should look better about your JS (compress, gzip, split to many files and upload them from different CDNs, move everything to $().ready, etc.)

Comments

0

My recommendation would be to have your initial PHP script JUST deliver the CSS and JS tags. Once those are loaded, use the JavaScript to make an AJAX call that gets the rest of the page then displays it. Or you can build the page in the JavaScript (which would allow you to use loading icons and the like to give a better indicator to the user that "the page is coming")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.