BoxF
ǝʌıʇɔǝdsɹǝd ɹnoʎ ǝɓuɐɥɔ
- Joined
- Dec 4, 2017
- Messages
- 51
- Likes
- 165
- Degree
- 0
Hello everyone, BoxF here.
When people often talk about SEO and sitespeed, you rarely hear people talking about remote files aside from... HOLY !#$@%#^ Remove some scripts you crazy monkey!
I've been playing around with some simple proof of concepts which allow you to reduce some of those external requests and still enable you to leverage their usability.
So far here's what I've gotten:
Let's kick some ass!
When people often talk about SEO and sitespeed, you rarely hear people talking about remote files aside from... HOLY !#$@%#^ Remove some scripts you crazy monkey!
So far here's what I've gotten:
PHP:
<?php
//Place me in your public_html root
$localpath = dirname(__FILE__);
//General Housekeeping
if (!file_exists($localpath.'/js')) {
mkdir($localpath.'/js', 0777, true);
}
//set local path
$localfile = $localpath.'/js/ga-local.js';
// local analytics path is now /js/ga-local.js don’t forget to update all references of Analytics.js to this path!
$remotefile = 'https://www.google-analytics.com/analytics.js';
$googlemd5 = md5_file($remotefile);
if(file_exists($localfile)){
$localmd5 = md5_file($localfile);
}
if($googlemd5 == $localmd5) {
echo "You're Local version of google analytics is up to the latest version.)";
die;
} elseif(copy($remotefile,$localfile)) {
echo "Success: Ga-local.js File is located here: ".$localfile;
} else {
echo "Import of Analytics.js failed.";
}
?>
But wait..
While this is still a working concept, there are some area's I want to add to this script in order to build it even further.
- CRON support for scheduling the updater
- Add Byte validation encase remote file moves or get's renamed to prevent NULL data in our local file
- Some sort of notification for when imports fail or files move
- Array support for supporting more than 1 file at a time
- Add Global PHP variables for Script Sources
If any of you guys have experience in similar tests like this I'd love to hear more!
Do you have any advice into roadblocks?
Do you have any advice into roadblocks?
IF NOT...
I'll keep posting my iterations so everyone can leverage bringing all of their scripts locally!
I'll keep posting my iterations so everyone can leverage bringing all of their scripts locally!
Let's kick some ass!
Last edited: