Load Random JS File When Page Refresh
2018-06-30, 09:03 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
Share This Thread :

2018-06-30, 09:34 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/...

.

Please check my latest thread: https://www.cpaelites.com/Thread-Snapchat-Q-A



[Image: giphy.gif]

Automate your daily work with Bots!
Then you'll have more time to sleep. ;-)
Reply
2018-06-30, 11:15 AM,
#3
(2018-06-30, 09:03 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, 11:46 AM,
#4
(2018-06-30, 11:15 AM)tirycm Wrote:
(2018-06-30, 09:03 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
  Free Landing Page Host Recommendation Please snaponsin 1 79 2019-03-21, 04:25 AM
Last Post: JustPlainLucas
  I have a 50k female Facebook page. how do i make money. umitsari 2 232 2019-03-01, 01:09 PM
Last Post: umitsari
  Anyone here tried to buy 1st page google gig on fiverr? Pixel8 14 1,313 2019-02-22, 12:11 PM
Last Post: CharlieHarper
  Free landing page that converts well Ragnar84 3 468 2018-12-11, 11:39 PM
Last Post: drkwrld
  Which free website builder is best to host landing page? timilak65 3 384 2018-12-10, 02:46 PM
Last Post: Mr. Burnham





About Us | Contact Us | CPA Elites | Advertise | Stats

© 2013-2019 CPA Elites Ltd
Enhanced by MyBB and WallBB
Return to top