Pages

Monday, July 16, 2018

How to Fix the Leverage Browser Caching?

What is Browser caching?
  • Browser stores web page files on a local computer when a user browses any web page.
  • "Leveraging" browser caching: When a webmaster has instructed browsers how their resources should be handled like what its expiration and what's the age of web page resources like css and js or any other media.

For resolve leverage browser caching error we need simple put below code into .htaccess file.

## EXPIRES HEADER CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/svg "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES HEADER CACHING ##

Monday, July 2, 2018

MYSQL Comma Seperated Rows | Concatenate multiple MySQL rows into one field

Tips Trick to Concatenate comma separated rows Value:

Suppose you want to show comma separate row value using mysql query and want output like below:

Mysql query to get favorite subject of Person :

SELECT subjects FROM user_subject_table WHERE user_id = 5; 

It will Give below output:

subjects
Computer
History
English
Chemistry

But you want to show comma separate in single row with user id then use below query:

SELECT user_id, GROUP_CONCAT(subjects SEPARATOR ', ') as fav_subject
FROM user_subject_table GROUP BY user_id

Output:

user_id          fav_subject
2                     English, Computer
5                     Computer, History, English, Chemistry

Advance Usage : 
1. Show Distinct subjects

SELECT user_id, GROUP_CONCAT(DISTINCT subjects  SEPARATOR ', ') as fav_subject

FROM user_subject_table GROUP BY user_id

2.  Show Subject Order by (ASC or DESC)

SELECT user_id , GROUP_CONCAT(subjects  ORDER BY subjects  ASC SEPARATOR ', ') as fav_subject FROM user_subject_table GROUP BY user_id