Can you create two asyncs in one
Can you create two asyncs in one cloudflare worker? Im trying to apply custom CSS & apply a cookie under a condition but the required responses are different. Not sure how to merge these together
20 Replies
We can just use a thread
Hey Kian. So check this out
I currently have this script running on all urls of my website
Pastebin
addEventListener('fetch', event => { event.passThroughOnExceptio...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
However, I would also like to run this on all urls of my website
Pastebin
/* Attempting to Incorporate Additional Styling as Well */async fun...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
And I am simply struggling to merge these two scripts together
In short
Script 1 performs a few different actions depending on some If statements
Script 2 changes custom CSS IF country is NOT US or Canada
@kiannh
https://developers.cloudflare.com/workers/runtime-apis/html-rewriter/#element is likely a more performant (and better) way of adding content at the end of the
<body>
element - other than that, it just sounds like a clean-up of the if
statements and adding the code into a single WorkerWe have so many projects going on here
I can push code to cloudflare for testing purposes as needed
try this
might not work, might have got some
if
statements the wrong way around
needs cleaning up but as a concept, probably worksThis code has been deployed if you would like to see how it works life. In the AM, I will also proceed with some testing, study this a bit, and let you know!
If there is anything I can do to help your community, reviews, shoutouts, post some of my code I have written, I would love to return the favor
Or, I can boost the server?
Updates
When not connected to VPN, International CSS is hidden
When connected to international VPN, International CSS is visible
Great news! However the syling is not actually applying on the frontend - for instance the entire website should be dark mode - I am checking this now
Looks like styling code is appearing outside of <style></style>
Resolved @kiannh, just forgot the <style type="text/css">etc</style> on the second StyleHandler
@kiannh, I would like to commission (unpaid) your support one more time
My Cache System (Cloudflare & WP-Rocket) are breaking my script at the plugin level to auto redirect based on visitor navigator.language
In other words, right when I clear my cache, and you visit ellasbubbles.com from a french device you will be redirected to ellasbubbles.com/fr
However, after about 2+ minutes when cache collects, this redirect stops working
So I am attempting to build a redirect at the Cloudflare Worker level to handle this and avoid cache issues
The URL format is: ellasbubbles.com + 2 letter language code + subdirectories
I am working on this now, but you might be able to help me much more efficiently
Cloudflare Community
HTTP Language and worker redirect
How can I use worker to redirect based on browser language something like this RewriteCond %{HTTP:Accept-Language} ^ar [NC] RewriteRule ^$ /ar/ [L,R=301]
I have started building this out in Dynamic/Redirect rules but this is going to get quite lengthy