Google Ads

Linux and Software: News, Reviews, Tutorials

December 3, 2017

Yet another HTML cache busting technique

If you are coding your web application or web site from the ground up then you may be already facing problems where changing individual files does not get reflected immediately. This is due to browsers caching some of the files to speed up loading performance and also to save bandwidths. The process of avoiding caching in the browsers is called cache busting. There are already a ton of solutions out there which can be applied to your HTML code to avoid caching where some are tedious to maintain and others are a breeze. Although not very well known technique here I am presenting how to use hashing technique to do HTML cache busting. This technique can be well applied to both client side or server side scripting languages as well as using any cryptographic hash functions. The method I have selected for my web development is client side PHP scripting language and SHA-1 hash function. Using this method the following HTML code shows how to import external CSS file with cache busting feature:
<link rel="stylesheet" <?php echo "href=\"style1.css?v=" . sha1_file('style1.css') . "\"" ?>>
In the above code, PHP script will inject HREF attribute into the link tag. The ?v=" . sha1_file('style1.css') code fragment will change each time the CSS file is modified as well as add a argument to the CSS file name which will force browsers to load the CSS file. As the SHA-1 hash function is unique each time for a particular CSS file data set the above code works well as intended.

The following code snippet shows that the same technique can be applied to import JavaScript files with cache busting feature:
<script <?php echo "src=\"load.js?v=" . sha1_file('load.js') . "\"" ?>></script>
Cheers!
Imam


July 4, 2017

Stop Ubuntu from freezing completely with Intel Bay Trail

Ubuntu and Linux kernel seem to suffer from a cpu state bug which completely freezes the system when doing graphics intensive tasks such as playing games or videos. Many processors suffer from this bug including the following Intel processors:
  • Celeron J1900
  • Celeron N2940
  • Celeron N2840
  • Celeron N2930
  • Pentium N3520
  • Pentium N3530
  • Pentium N3540
To see whether you have one of the above processor put the following command in the terminal:

cat /proc/cpuinfo | grep 'model name'


This bug can easily be fixed by installing proper Microcode files and changing c-state flag for Linux kernel.

First step is to make sure you have Ubuntu microcode package installed by putting the following command in the terminal:

sudo apt-get install intel-microcode


Then, remove the existing microcode files by running the following command in the terminal as they are not recent:

sudo rm /lib/firmware/intel-ucode/*


After then, install Intel Microcode files by downloading Microcode package from the following site:

https://downloadcenter.intel.com/download/26798/Linux-Processor-Microcode-Data-File


Download the microcode*.tgz file and extract it in the Home folder. Now copy the extracted microcode files to system folder by opening a terminal in intel-ucode folder and running the following command:

sudo cp * /lib/firmware/intel-ucode/


Now edit the grub file to change c-state kernel flag by opening grub file in /etc folder by putting the following command:

sudo gedit /etc/default/grub


In the grub file under the line containing GRUB_CMDLINE_LINUX_DEFAULT=, add the following intel_idle.max_cstate=2, so the line should look like the following line:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_idle.max_cstate=2"


Now, save and close the grub file and put the following command in the terminal to update boot loader to reflect kernel flag:

sudo update-grub


Done! Now just reboot the system and check whether microcodes are loaded properly by running the following command in the terminal:

dmesg | grep microcode


You should be able to see something like following as output of above command:

[ 3.168100] microcode: CPU0 sig=0x30678, pf=0x8, revision=0x829
[ 3.168138] microcode: CPU1 sig=0x30678, pf=0x8, revision=0x829
[ 3.168445] microcode: Microcode Update Driver: v2.01 <tigran@aivazian.fsnet.co.uk>, Peter Oruba


Cheers!
Imam