const PRISM_API_KEY = 'prism_jrfvXGHXOMscbgOD7NrcMgO5K2oQ4OqZ';
const PRISM_ENDPOINT = 'https://prism.trakkr.ai';
const PRISM_TIMEOUT = 1000; // ms
// Crawler patterns to optimize for (customizable)
const AI_CRAWLERS = [
'gptbot',
'chatgpt-user',
'oai-searchbot',
'claudebot',
'claude-user',
'claude-searchbot',
'perplexitybot',
'meta-externalagent',
'google-extended',
'cohere-ai',
'applebot-extended',
'amazonbot',
'baiduspider',
'bytespider'
];
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const url = new URL(request.url);
// Quick bypass for non-HTML requests
if (url.pathname.match(/\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot)$/i)) {
return fetch(request);
}
// Check if AI crawler
const ua = (request.headers.get('user-agent') || '').toLowerCase();
const isAICrawler = AI_CRAWLERS.some(bot => ua.includes(bot));
if (!isAICrawler) {
return fetch(request);
}
// Detect crawler type
const crawlerType = AI_CRAWLERS.find(bot => ua.includes(bot)) || 'unknown';
try {
// Call Prism API with tight timeout
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), PRISM_TIMEOUT);
const prismResponse = await fetch(PRISM_ENDPOINT, {
method: 'POST',
headers: {
'X-API-Key': PRISM_API_KEY,
'X-Crawler-UA': ua.substring(0, 200),
'X-Target-URL': url.toString(),
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: url.toString(),
pathname: url.pathname,
crawler: crawlerType
}),
signal: controller.signal
});
clearTimeout(timeoutId);
// Handle rate limiting
if (prismResponse.status === 429) {
console.log('Prism limit reached');
return fetch(request);
}
// Handle successful optimization
if (prismResponse.ok) {
const data = await prismResponse.json();
if (data.optimizedHTML) {
return new Response(data.optimizedHTML, {
status: 200,
headers: {
'Content-Type': 'text/html;charset=UTF-8',
'X-Prism-Optimized': 'true',
'X-Prism-Cache': data.cache || 'MISS'
}
});
}
}
} catch (error) {
// Timeout or error - serve original immediately
console.error('Prism error:', error.message);
}
// Default: serve original content
return fetch(request);
}
Waste Footprint Calculator
Learn the savings you can make today - no strings attached.
1. Fill out the relevant form 2. Receive custom report in your inbox based on real data from our clients 3. Book a time with the team to discuss your results
Click here to view the walkthrough of the calculator.
Oops! Something went wrong while submitting the form.
*This tool is constantly being updated and improved. All waste and recycling data is being updated on a regular basis so reports may vary. If there are more data points you are interested in, please let us know. This analysis assumes an even distribution of sales across the markets you indicate and system losses associated with the recycling system from consumer to end-market. Selling into specific regions more than others can dramatically affect results. Please contact evan@scrappzero.com for the methodology of the report.