Load Random JS File When Page Refresh
2018-06-30, 05:33 AM,
#1
I'm working on new website that I need to load different JS file every time the page refresh, kind of split test.
Searching around the web and found some, no work.
I found the method on this page of stakeoverflow: https://stackoverflow.com/questions/3591...ge-refresh
Code:
<link href="/styles/<?php echo mt_rand(1, 5); ?>.css" rel="stylesheet" type="text/css"/>
look like it will work for js too. But I dont know php at all.

How can I load random js file every time the page refresh?
let's I have abc.js, every.js, well.js, notable.js and I want to load them randomly.
Many thanks.
Reply
2018-06-30, 06:04 AM,
#2
You should consider the following topics first, before you start to implement something like this:

- What happens if the same visitor returns? (solution: cookies [bad], session handling [good])
- How to handle/bypass the browser cache?
- How to handle/bypass possible proxy caches?
- AdBlockers/AV tools could detect your current method as spam/malware/...

.


[Image: giphy.gif]

Automate your daily work with Bots!
Then you'll have more time to sleep. ;-)
Reply
2018-06-30, 07:45 AM,
#3
(2018-06-30, 05:33 AM)immart247 Wrote: I'm working on new website that I need to load different JS file every time the page refresh, kind of split test.
Searching around the web and found some, no work.
I found the method on this page of stakeoverflow: https://stackoverflow.com/questions/3591...ge-refresh
Code:
<link href="/styles/<?php echo mt_rand(1, 5); ?>.css" rel="stylesheet" type="text/css"/>
look like it will work for js too. But I dont know php at all.

How can I load random js file every time the page refresh?
let's I have abc.js, every.js, well.js, notable.js and I want to load them randomly.
Many thanks.

$jsAr = ["abc.js", "every.js", "well.js", "notable.js"];
$js = $jsAr[array_rand($jsAr)];

<link href="/styles/<?php echo $js; ?>" rel="stylesheet" type="text/css"/>
Reply
2018-06-30, 08:16 AM,
#4
(2018-06-30, 07:45 AM)tirycm Wrote:
(2018-06-30, 05:33 AM)immart247 Wrote: I'm working on new website that I need to load different JS file every time the page refresh, kind of split test.
Searching around the web and found some, no work.
I found the method on this page of stakeoverflow: https://stackoverflow.com/questions/3591...ge-refresh
Code:
<link href="/styles/<?php echo mt_rand(1, 5); ?>.css" rel="stylesheet" type="text/css"/>
look like it will work for js too. But I dont know php at all.

How can I load random js file every time the page refresh?
let's I have abc.js, every.js, well.js, notable.js and I want to load them randomly.
Many thanks.

$jsAr = ["abc.js", "every.js", "well.js", "notable.js"];
$js = $jsAr[array_rand($jsAr)];

<link href="/styles/<?php echo $js; ?>" rel="stylesheet" type="text/css"/>
this works for me. rep+
thank you very much.
Reply


Related Threads
Thread Author Replies Views Last Post
  HQ Mediafire Landing Page mayank 6 3,880 2020-10-27, 08:16 PM
Last Post: ychouhad
  S.O.S Newbie need help! cpagrip url/file locker Hektor26 12 3,066 2020-08-08, 10:28 PM
Last Post: cyberdon
  Landing Page (Download Page Media Fire) AliAbdrrazak 0 428 2020-08-07, 07:24 PM
Last Post: AliAbdrrazak
  Blogger single page movie template? Doone 7 1,580 2020-06-16, 04:18 AM
Last Post: loginerror
  how can I Set up a Landing Page in bolgger riadh9 7 479 2020-05-31, 08:12 PM
Last Post: riadh9





About Us | Contact Us | CPAElites | Advertise | Stats

Copyright © 2013 - 2020 by (company to be announced later)
Temporarily (!) powered by MyBB, fixed (repaired) and enhanced by Charlie Harper (GitHub) aka Charles Francis Harper (Wikipedia)
Return to top
This forum uses Lukasz Tkacz MyBB addons.