I have a page with a lot of data validation on it (for a form). But the validation is not actually executed until the user hits Submit. The page loads really slow. Is there a way to control how a page loads so that, as I suspect, the validation Javascript loads after the form actually displays?

I want the user to see the page/form displayed as quickly as possible while I recognize that the the page load may not be complete because its still loading the validation routines.

Any ideas on what I can do to speed it up?

validation Javascript loads after the form actually displays?

Placing the <script> just before the </body> tag will do what you want but it is not likely that doing so will, by itself, significantly improve the perceived load time. Something else is almost certainly going on.

If you have a huge validation script that you think is causing the slowdown, try putting it into a separate js file and referencing it from the page. This should cause the browser to cache the js file and not load it with every page request (only the first time the page is loaded).
But I agree with fxm, there is probably something else slowing it down.

dont suppose you might consider posting the problem code, for examination
considerations... musings...

  • If on a *nix server have you employed mod_gzip for any files html php js css larger than ~5k, remarkable difference
  • minified javascripts
  • stripped redundant whitespace from the files,indented code is pretty, but functionally stupid
  • stripped inline css to an external file
  • formatted images appropriately for the purpose
  • used css not images wherever posible
  • not encapsulated the form in a table,,, no part of a table renders until the table is entirely downloaded
    there is a huge amount of extra code to set out a table

mod_gzip = GOLD

eg script.js => 20KB,, script.js.php has 3 extra lines and is 4.2KB

<?php header ('content-type: text/javascript');
ob_start("ob_gzhandler"); ?>
/*huge amount of javascript*/
<?php ob_flush(); ?>

<script type='text/javascript' src='script.js.php'></script> just thoughts

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.