-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathresource_optimizer.py
More file actions
42 lines (36 loc) · 1.5 KB
/
resource_optimizer.py
File metadata and controls
42 lines (36 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from PyQt6.QtWebEngineCore import QWebEngineProfile, QWebEngineSettings
from PyQt6.QtCore import QTimer
class ResourceOptimizer:
@staticmethod
def optimize_web_engine():
"""Ottimizza le impostazioni del motore web"""
# Configurazione profilo
profile = QWebEngineProfile.defaultProfile()
# Configurazione della cache
profile.setHttpCacheMaximumSize(100 * 1024 * 1024) # 100 MB
profile.setHttpCacheType(QWebEngineProfile.HttpCacheType.DiskHttpCache) # Cache su disco
return profile
@staticmethod
def setup_lazy_loading(browser):
"""Implementa caricamento lazy delle risorse"""
def preload_critical_resources():
# Logica di precaricamento risorse critiche
browser.page().runJavaScript("""
// Ottimizza caricamento risorse
document.querySelectorAll('img').forEach(img => {
img.loading = 'lazy';
});
""")
# Carica risorse dopo un breve ritardo
QTimer.singleShot(1000, preload_critical_resources)
class ResourceInterceptor:
"""Interceptor per bloccare risorse non necessarie"""
def __init__(self):
self.blocked_domains = [
'doubleclick.net',
'googlesyndication.com',
'ads.twitter.com'
]
def should_block_request(self, url):
"""Determina se bloccare una richiesta"""
return any(domain in url for domain in self.blocked_domains)