Now a day’s Technology is fast moving, users expect fast and quick information. Now users have a low tolerance for slow loading websites. For user detainment and ensure better customer satisfaction with help to hire php developer, this blog is focusing on an aspect of improving web application and it’s development.
Assets Are:
Assets are nothing but files like CSS, Image, JavaScript etc. Which used to create the frontend of your website. To make the website load faster there are many ways.
4 EASY TO USE METHODS BY OUR DEVELOPERS(TESTED AND TRIED):
Assets Minification – Removing redundant and unwanted code without affecting the resource is called minification. You can find more information here.
Assets Cache – Our focus is on browser caching, as per Wikipedia, the cache is a hardware or software component which stores data and future requests for that data can be served faster. After applying cache to your browser, the browser “remembers” the assets which were loaded.
After requesting a particular web page, the browser runs multiple requests to the server to display the page and load its assets PHP web developer. By utilizing browser caching, asset files get stored in the browser cache, which decreases the page load time for all pages which share the assets.
Use GZIP compression – Every modern browser handle GZIP compression. Compressing your files will decrease the data transit time, which decrease the page load time. For configuration info about GZIP compression depending on your web server Apache GZIP, Apache DEFLATE, NGINX GZIP information resource available online.
Content Delivery Network (CDN) - CDN is a topographically dispersed gathering of servers which cooperate to give quick conveyance of Internet content. at the point when the program asks for your site page, it downloads the (advantage) records from the closest server and abatement the page stack time.
However, caching assets on your browser creates another problem. If we modify the file content on the server, the browser will not know about it. All subsequent requests to the webpage will load the cached file, as it is cached in the browser, you have to clear cache, and then modified the file from the server will be loaded in the browser From clear this problem, we would need to force the browser to request for the modified file. If you want to create the new website you can take help from TechTIQ Solutions. TechTIQ has an expert team in PHP programmer.
Fingerprinting Of Asset
Fingerprinting of Asset is a system that powers a connection between the filename and its substance. At the point when the substance of a document is changed, resource fingerprinting adjusts the relating filename by this it guarantees that the remote customers ask for a crisp duplicate of the record.
Forcing your browser to load the modified file is called as asset fingerprinting or known as cache busting.
For Example, the extract of a PHP Developer (code) used to achieve the same in CodeIgniter framework which can be used across all frameworks/languages.
common_helper.phP
function asset_url($filename = '')
{
if(ENVIRONMENT == 'development') {
return site_url('assets/'.$filename).'?ver='.md5_file('assets/'.$filename);
}
$explodedFileName = explode('.', $filename);
$fileExtension = array_pop($explodedFileName);
$filename = implode('.', $explodedFileName).'-'.md5_file('assets/'.$filename).'.'.$fileExtension;
return site_url('prod/'.$filename);
}
Asset.php
<?php
class Asset {
public static function fingerprint_assets() {
$source_directory = 'assets';
$destination_directory = 'prod';
exec('rm -rf '.$destination_directory);
self::recursive_copy($source_directory, $destination_directory);
}
private static function recursive_copy($source_directory, $destination_directory) {
$dir = opendir($source_directory);
mkdir($destination_directory);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($source_directory.'/'.$file) ) {
self::recursive_copy($source_directory.'/'.$file, $destination_directory .'/'. $file);
}
else
{
$explodedFileName = explode('.', $file);
$fileExtension = array_pop($explodedFileName);
$destinationFileName = implode('.', $explodedFileName).' '.md5_file($source_directory.'/'.$file).'.'.$fileExtension;
copy($source_directory . '/' . $file,$destination_directory . '/' . $destinationFileName);
}
}
}
closedir($dir);
}
}
Asset::fingerprint_assets();
Give us a chance to consider that every one of your advantages live in the asset folder. Presently we execute the document Asset.php from the base way of your CodeIgniter application which creates the fingerprinted records for generation use(prod folder). When you utilize the accompanying code in your design
<link rel="stylesheet" href="<?php echo asset_url('css/style.css'); ?>">
<script src="<?php echo asset_url('js/zepto.js'); ?>"></script>
The helper function produces the following output:-
<linkrel="stylesheet"href="https://example.com/prod/css/style-8b6aee697a2a565794c5b38a5f80b02a.css">
<script src="https://example.com/prod/js/zepto-50a4556b0089cfa1cb61e88ea23bbcce.js"></script>
The assets filename is appended with the md5_sum value of the file. When the asset file is modified, the md5_sum of the file changes which generates a new filename. As your browser does not have the new file, the browser requests a fresh copy from the server which loads the new asset to the user.
The above code can be improved. Rather than executing the method asset_url() for each request of your page load – another data type can be referenced. Create a HASH (key => value array) every time the production assets are fingerprinted. Reference this HASH in the function asset_url(). I leave this to you, the developer to figure out.
If you use this procedure, all asset files on your production will be appended with a fingerprint. This should further speed up your website and avoid caching problems. read more blog from here Crucial tips: What to Look for while hiring a PHP developer?
Author Bio: Daniel Dixon a freelance, blogger and SEO Consultant @ TechTIQ Solutions. He writes unique and research-driven content about Business and Trending Technologies. For more updates about Blogs and Technologies, connect Daniel Dixon with Facebook and LinkedIn.
How to develop faster web applications using PHP asset?
Reviewed by David Piterson
on
August 17, 2018
Rating:
No comments: