Posts Tagged ‘ frontend

JavaScript String.replace with regex

I often use String.replace in JavaScript whenever I have to use JavaScript. Today was the day that I ended up with using it for my work. I know that String.replace supports regular expression to match your string, but I was not clear if I could use “capturing groups” and “quantifiers”. As I guessed, I was able to use quantifiers in the replace string like the sample below:

    var link_template = '<ol>\
        <li><label>Link 1 Title:</label><input class="text" id="relLink1title" name="relLink{1}title" value="" /></li>\
        <li><label>Link 1 URL:</label><input class="text" id="relLink1url" name="relLink{1}url" value="" /></li>\
        <li><label>Link 1 Img URL:</label><input class="text" id="rellink1imgurl" name="rellink{1}imgurl" value="" /></li>\
        <li class="btn"><span><a href="#" class="new-related-link">Add a New Link</a> | <a href="#" class="remove-related-link">Remove</a></span></li>\
        </ol>';
 
    link_template = link_template.replace(/(<label>.*?)(\d)(.*?<\/label>)/im, '$1 2 $2');

Initial Page Load – FE Performance Tuning

1. Introduction

Why is the site performance so important? The poor site performance impacts company’s revenue and user’s engagement.

  • Shopzila: 5 seconds speed up resulted in a 25% increase in page views, 10% increase in revenue, a 50% reduction in hardware, and a 120% increase traffic from Google.
  • Amazon: every 100ms of latency cost them 1% in sales
  • google: extra .5 seconds in search page generation time dropped traffic by 20%
  • a broker could lose $4 million in revenues per millisecond if their electronic trading platform is 5 milliseconds behind the competition.
  • facebook: regardless of site speed, users spend around the same amount of time on facebook, which means if the site is running slowly users are going to be seeing fewer pages in the same amount of time.

So the conclusion is that fast site is better.

Read more