I made Ajax Like Button. After pressing a similar button, it takes about 800 ms - 1100 ms to perform the following actions:
- Open
insertlike.php page in background using jQuery - Add this to the database at
insertlike.php - Confirm like this using JSON
- Turn the button color as green.
But Facebook's and the other site Like Button works really fast.
Does Facebook directly change the color of the button as on a click, or does it only change after adding this to the database?
This is my code:
index.php to make ajax request
$(".insertlike").submit(function(e) { var data = $(this).serialize(); var url = $(this).attr("action"); var form = $(this); $.post(url, data, function(data) { try { data = JSON.parse(data); $(form).children("button").html(data.addremove + " Watchlist"); $(form).children("input#addedornotsend").attr("value",data.addedornotsend); } catch (e) { console.log("json encoding failed"); return false; } }); return false; });
Code inside insertlike.php
<?php // Add to Database code $response = new \stdClass(); $response->addremove = "".$addremove.""; $response->addedornotsend = "".$addedornotsend.""; die(json_encode($response));
Any way to insert the same button speed? Maybe some php cache trick or something like that? I'm still a beginner.
Edit: this is a server response time rate test:

source share