Which code loads faster?


up to now I’m still wondering what code loads faster - check below

  1. echo '<h2 class="ptitle">' . $theme_search_header_label . '</h2>';


  1. <h2 class="ptitle"><?php echo $theme_search_header_label; ?></h2>


I don’t think there’s any significant difference but the second should load “faster”. But the difference is negligible.

thanks for that… What about this

<h2 class="ptitle"><?php echo $theme_search_header_label; ?></h2>
when you view source it would result like this
<h2 class="ptitle">Example</h2>



<?php echo $theme_search_header_label; ?>

` when you view source it would result like this `




2nd should be faster :joy:
And those spaces could be remove if you remove linebreaks and hidden spaces

does space adds loading time when site is loaded?

Space dose not take to much time to load. its just like a character…

if you enter code like below.
echo "<h2 class="ptitle">".$title."</h2>";
<h2 class="ptitle"><?php echo $title; ?></h2>

There is no big difference in loads… and also space dose not matter.

the first one will take the whole string into php generate where as the second one will be take only the php part which will echo / return the string from variable…

and also if we have more opening and closing tags php. it may slow down a bit but not much.
eg having more than 1000 of open and closing tags :wink:

Just shared my thoughts. i might be wrong. but i think it should not be :slight_smile:

Your bottleneck is somewhere else. Sincerely.

Yes, you could reduce the loading time by ~1ms