It was a random thought 🤔 in my mind that how will we monitor our website's traffic from backend languages like php 🤦🏽♂️ because in frontend you can put the script tags of many websites like Google Analytics, Plausible, Addthis to know about your traffic.
But for Specially sites like API providing site (i.e. WhollyAPI). Which give the results in JSON format or any other and can't print script tag on html. ⚡
Frontend (i.e. HTML)
So, Then I remembered I was using this trick in frontend for example you are using
bootstrap
on your website and you are using CDN like this :-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css">
You should shorten the URL https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css
with bit.ly (bit.ly/bscdn) and Use the CDN Like this :-
<link rel="stylesheet" href="https://bit.ly/bscdn
">
Because bit.ly doesn't block cross origin it will work same but you are getting a plus point as analytics on your bit.ly dashboard.
What If you are not Using any CDN or external library
You can use Blank Files Instead of a bootstap or something containig URLs
You can get blank files CDNs from here.
Github :- https://github.com/SH20RAJ/blankfiles
CDNs
Txt File :-
https://cdn.jsdelivr.net/gh/SH20RAJ/blankfiles/blank.txt
Css File :-
https://cdn.jsdelivr.net/gh/SH20RAJ/blankfiles/blank.css
JS File :-
https://cdn.jsdelivr.net/gh/SH20RAJ/blankfiles/blank.js
and Use these CDNs to short using bit.ly
Backend (i.e. php)
In php you can echo the link tag containing shortened URL but here a thing when you don't want to show this on website. You want all the process in backend.
Here https://bit.ly/blank-txt will refer to https://cdn.jsdelivr.net/gh/SH20RAJ/blankfiles/blank.txt?devarticle
So You can Use file_get_contents();
at last of your php code.
Use alternative function for other languages.
file_get_contents('https://bit.ly/blank-txt');
So, that you file call will be done on server side and no extra load on server or internet of user 🤭 because the files are blank. 😌
Top comments (0)