<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="it">
	<title>Andrea Verlicchi</title>
	<subtitle>Rendo il web più veloce e più usabile</subtitle>
	<link href="https://andreaverlicchi.eu/it/feed/feed.xml" rel="self"/>
	<link href="https://andreaverlicchi.eu/"/>
	<updated>2026-07-27T00:00:00Z</updated>
	<id>https://andreaverlicchi.eu/</id>
	<author>
		<name>Andrea Verlicchi</name>
		<email>andrea.verlicchi@gmail.com</email>
	</author>
	
	<entry>
		<title>Claude vs Gemini, i miei casi d&#39;uso</title>
		<link href="https://andreaverlicchi.eu/it/blog/claude-vs-gemini-i-miei-casi-d-uso/"/>
		<updated>2026-07-27T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/claude-vs-gemini-i-miei-casi-d-uso/</id>
		<content type="html">&lt;p&gt;C&#39;è molto hype e si fa molto parlare di Claude ed Anthropic, soprattutto dopo l&#39;annuncio di Fable 5 e, ultimamente, di Opus 5. Lo uso Claude eh, mica dico che non lo uso! Però per molte cose preferisco ancora &lt;strong&gt;Gemini 3.6 Flash&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Il motivo è semplice: sebbene la mia azienda abbia adottato Claude in full e ne spinga fortemente l&#39;utilizzo, essendo molto in contatto con Google ed altri sviluppatori Google per via del programma &lt;strong&gt;GDE (Google Developer Experts)&lt;/strong&gt;, sento pareri entusiasti anche sul fronte Gemini. Quindi voglio continuare a provarli e utilizzarli entrambi.&lt;/p&gt;
&lt;p&gt;Non dico che per me si equivalgano in tutto, ma ci sono casi d&#39;uso ben precisi in cui preferisco l&#39;uno e casi in cui preferisco l&#39;altro. Ecco come li ho divisi nel mio workflow quotidiano:&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/vflIjejSBt-648.webp 648w, https://andreaverlicchi.eu/img/vflIjejSBt-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/vflIjejSBt-648.jpeg 648w, https://andreaverlicchi.eu/img/vflIjejSBt-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea pensieroso con due fumetti che mostrano i loghi di Anthropic Claude e Google Gemini.&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/vflIjejSBt-648.jpeg&quot; width=&quot;1296&quot; height=&quot;723&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Claude o Gemini? I due fumetti rappresentano le mie opzioni quotidiane di IA.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;claude-in-claude-desktop&quot; tabindex=&quot;-1&quot;&gt;Claude in Claude Desktop &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/claude-vs-gemini-i-miei-casi-d-uso/#claude-in-claude-desktop&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Task complessi e multi-tool&lt;/strong&gt;: Lunghi task che prevedono lettura e scrittura su più strumenti aziendali, tra cui lo Slack aziendale, Hex, o altri tool di integrazione.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;claude-in-claude-code&quot; tabindex=&quot;-1&quot;&gt;Claude in Claude Code &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/claude-vs-gemini-i-miei-casi-d-uso/#claude-in-claude-code&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sviluppo di codice complesso&lt;/strong&gt;: Per task di codice impegnativi (quelli che richiedono un bel po&#39; di ragionamento, come i major release refactoring), mi affido ai modelli &lt;em&gt;Fable 5, Opus 4.8 o Sonnet 5&lt;/em&gt;. Spesso questi task prevedono l&#39;integrazione diretta con tool via CLI come GitLab (&lt;code&gt;glab&lt;/code&gt;), Google Cloud (&lt;code&gt;gcloud&lt;/code&gt;), o i nostri server MCP interni.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Troubleshooting di Git (con Haiku)&lt;/strong&gt;: Per uscire da situazioni complicate con &lt;code&gt;git&lt;/code&gt; (ad esempio quando devo prendere gli ultimi commit fatti per errore su &lt;code&gt;main&lt;/code&gt; e spostarli in un feature branch, oppure forzare il push su &lt;code&gt;staging&lt;/code&gt; ignorando quello che c&#39;era già — non giudicatemi: non ho quasi mai usato &lt;code&gt;git&lt;/code&gt; da riga di comando, sono pigro!).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;gemini-in-antigravity-antigravity-ide&quot; tabindex=&quot;-1&quot;&gt;Gemini in Antigravity / Antigravity IDE &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/claude-vs-gemini-i-miei-casi-d-uso/#gemini-in-antigravity-antigravity-ide&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Task di codice mediamente complessi&lt;/strong&gt;: Per feature medio-grandi utilizzo &lt;strong&gt;Gemini 3.6 Flash (high)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DevTools e analisi di performance&lt;/strong&gt;: Per task che prevedono di utilizzare i DevTools for Agents e magari fare analisi approfondite di performance web, uso &lt;strong&gt;Gemini 3.6 Flash (medium)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Manutenzione ed evoluzione del blog&lt;/strong&gt;: Per lavorazioni varie a questo blog (ad esempio di recente l&#39;ho tradotto interamente in italiano, ho creato skill personalizzate per creare nuovi blog post, etc.), uso &lt;strong&gt;Gemini 3.6 Flash (medium/high)&lt;/strong&gt;. Spoiler: questo stesso blog post, compresa l&#39;immagine di copertina, è stato generato proprio con Antigravity e Gemini 3.6 Flash (Medium)!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;gemini-web-desktop-account-personale&quot; tabindex=&quot;-1&quot;&gt;Gemini (web / desktop) – Account Personale &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/claude-vs-gemini-i-miei-casi-d-uso/#gemini-web-desktop-account-personale&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Per domande sulla vita, l&#39;universo e tutto quanto (tanto la risposta è sempre &lt;a href=&quot;https://it.wikipedia.org/wiki/Risposta_alla_domanda_fondamentale_sulla_vita,_l%27universo_e_tutto_quanto&quot;&gt;42&lt;/a&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Accoglienza gattini&lt;/strong&gt;: Come accogliere due cuccioli di gatto non avendo mai avuto animali (una lunga chat ancora attiva dopo un mese!).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Alimentazione e nutrizione&lt;/strong&gt;: Consigli sull&#39;alimentazione e piano alimentare (diverse chat generate mensilmente con Gem sempre aggiornati, per oltre 1 anno).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Progetti di casa&lt;/strong&gt;: Dimensionare correttamente un impianto fotovoltaico (chat fissata che mi servirà a breve).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;gemini-web-desktop-account-aziendale&quot; tabindex=&quot;-1&quot;&gt;Gemini (web / desktop) – Account Aziendale &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/claude-vs-gemini-i-miei-casi-d-uso/#gemini-web-desktop-account-aziendale&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Per domande puramente work-related:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Analisi di codice&lt;/strong&gt;: Analisi di librerie JS minificate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ottimizzazione SQL&lt;/strong&gt;: Comparazione della complessità e dei costi delle query SQL.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Debugging di errori&lt;/strong&gt;: Analisi di stack trace o errori Python / JavaScript poco chiari.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Workflow Slack&lt;/strong&gt;: Richieste su come realizzare automazioni e feature avanzate in Slack (workflows, app, automations).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;gemini-web-desktop-entrambi-gli-account&quot; tabindex=&quot;-1&quot;&gt;Gemini (web / desktop) – Entrambi gli account &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/claude-vs-gemini-i-miei-casi-d-uso/#gemini-web-desktop-entrambi-gli-account&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ci sono poi casi d&#39;uso trasversali per cui Gemini è il mio punto di riferimento sia sul profilo personale che aziendale:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Ricerche web persistenti&lt;/strong&gt;: Ricerche i cui risultati voglio che rimangano salvati in una history accessibile, anziché andare persi per sempre &lt;em&gt;come lacrime nella pioggia&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Analisi di documenti e file&lt;/strong&gt;: Analisi di file caricati per estrarre informazioni ben organizzate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Domande tech e configurazioni&lt;/strong&gt;: Risolvere dubbi tecnici, come configurare strumenti o far comunicare servizi tra loro, oppure capire come funzionano internamente alcuni aspetti dei modelli AI.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Brainstorming e presentazioni&lt;/strong&gt;: Discussione e generazione di idee su come preparare una presentazione.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;In conclusione: non esiste un unico modello &amp;quot;vincitore&amp;quot; assoluto per ogni esigenza. Sperimentare con entrambi permette di sfruttare il meglio di ciascun ecosistema e di adattare lo strumento giusto al task specifico!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Dovremmo smettere di usare la parola &quot;Responsive&quot; per il design?</title>
		<link href="https://andreaverlicchi.eu/it/blog/should-we-stop-using-the-word-responsive-for-design/"/>
		<updated>2026-07-07T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/should-we-stop-using-the-word-responsive-for-design/</id>
		<content type="html">&lt;p&gt;Nel lontano 2010, Ethan Marcotte ha coniato il termine &lt;a href=&quot;https://ethanmarcotte.com/books/responsive-web-design/&quot;&gt;Responsive Web Design&lt;/a&gt;. Da allora, abbiamo usato &amp;quot;responsive&amp;quot; per descrivere un sito web che adatta il suo layout alle dimensioni del viewport. Griglie fluide, immagini flessibili, media queries.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Xu114XHN6q-648.webp 648w, https://andreaverlicchi.eu/img/Xu114XHN6q-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/Xu114XHN6q-648.jpeg 648w, https://andreaverlicchi.eu/img/Xu114XHN6q-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Uno sviluppatore pensieroso guarda schermi che mostrano siti web responsive e app adattive, chiedendosi informazioni sulla terminologia.&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/Xu114XHN6q-648.jpeg&quot; width=&quot;1296&quot; height=&quot;723&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Dovremmo usare &quot;adattivo&quot; per i layout e &quot;responsive&quot; per le performance?&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Per un certo periodo abbiamo cercato di separarlo dal design &amp;quot;adattivo&amp;quot; (adaptive). A quel tempo, i siti web &amp;quot;adattivi&amp;quot; avevano una cattiva reputazione perché di solito si affidavano al rilevamento del dispositivo lato server (device detection) e allo sniffing dello user-agent per servire codice HTML e CSS completamente diverso al browser. Poiché lo sniffing UA era fragile, la community web ha voluto prenderne le distanze. Il modello responsive di Ethan serviva lo stesso identico codice a tutti, lasciando che fosse il browser a fare il lavoro. Il termine &amp;quot;Responsive&amp;quot; ha vinto la guerra del vocabolario, e &amp;quot;adattivo&amp;quot; è diventato associato a layout obsoleti rilevati dal server.&lt;/p&gt;
&lt;p&gt;Ma arriviamo a oggi: questi termini si sono divisi in modi che causano una reale confusione.&lt;/p&gt;
&lt;h2 id=&quot;la-definizione-mobile-di-adaptive-android-e-ios&quot; tabindex=&quot;-1&quot;&gt;La definizione mobile di &amp;quot;adaptive&amp;quot; (Android e iOS) &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/should-we-stop-using-the-word-responsive-for-design/#la-definizione-mobile-di-adaptive-android-e-ios&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se guardiamo allo sviluppo di app mobili moderne — sia su Android che su iOS — la parola &lt;strong&gt;&amp;quot;adaptive&amp;quot;&lt;/strong&gt; (adattivo) è lo standard.&lt;/p&gt;
&lt;p&gt;Google la usa massicciamente per il design delle app Android. Con la diffusione di smartphone pieghevoli e tablet, le app non possono semplicemente allargarsi per riempire lo schermo. Hanno bisogno di ristrutturare completamente il proprio layout. Nella loro &lt;a href=&quot;https://developer.android.com/design/ui/mobile/guides/layout-and-content/adapt-layout&quot;&gt;guida sui layout adattivi&lt;/a&gt;, il focus è interamente sui layout &amp;quot;adaptive&amp;quot; (ovvero che cambiano la struttura del layout in base a breakpoint e stati di piegatura del dispositivo), mentre i concetti &amp;quot;responsive&amp;quot; (come il dimensionamento fluido) sono visti solo come una base di partenza.&lt;/p&gt;
&lt;p&gt;Apple segue una logica simile. Nelle loro &lt;a href=&quot;https://developer.apple.com/design/human-interface-guidelines/layout&quot;&gt;Human Interface Guidelines per il Layout&lt;/a&gt;, inquadrano gli aggiustamenti di layout attorno al concetto di &lt;strong&gt;&amp;quot;Adaptability&amp;quot;&lt;/strong&gt; (Adattabilità) piuttosto che di &amp;quot;Responsiveness&amp;quot;. Guidano gli sviluppatori a creare interfacce che si adattano perfettamente a diversi dispositivi, dimensioni di schermo e orientamenti usando classi di dimensione (size classes) e strutture adattive.&lt;/p&gt;
&lt;p&gt;Quindi, nel mondo delle app mobili, l&#39;adattamento alle dimensioni dello schermo viene costantemente chiamato design &lt;em&gt;adaptive&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id=&quot;la-definizione-di-responsiveness-nelle-performance-web&quot; tabindex=&quot;-1&quot;&gt;La definizione di &amp;quot;responsiveness&amp;quot; nelle performance web &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/should-we-stop-using-the-word-responsive-for-design/#la-definizione-di-responsiveness-nelle-performance-web&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Allo stesso tempo, nel mondo delle performance web — dove trascorro molto del mio tempo — la parola &amp;quot;responsive&amp;quot; ha assunto un significato completamente diverso.&lt;/p&gt;
&lt;p&gt;Quando gli ingegneri delle performance dicono di voler rendere una pagina &amp;quot;responsive&amp;quot;, non parlano affatto di viewport o media query. Parlano di &lt;strong&gt;interattività&lt;/strong&gt;. Nello specifico, di quanto velocemente il browser reagisce agli input dell&#39;utente.&lt;/p&gt;
&lt;p&gt;Con la metrica di Google &lt;a href=&quot;https://web.dev/inp/&quot;&gt;Interaction to Next Paint (INP)&lt;/a&gt;, la &amp;quot;responsiveness&amp;quot; viene misurata in millisecondi. Se un utente tocca un bottone e la pagina si blocca per 300 ms, quel sito web ha una scarsa reattività (responsiveness).&lt;/p&gt;
&lt;h2 id=&quot;la-collisione-terminologica&quot; tabindex=&quot;-1&quot;&gt;La collisione terminologica &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/should-we-stop-using-the-word-responsive-for-design/#la-collisione-terminologica&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Questo ha creato un bel pasticcio.&lt;/p&gt;
&lt;p&gt;Se un product manager dice: &lt;em&gt;&amp;quot;Dobbiamo rendere questo sito web più responsive.&amp;quot;&lt;/em&gt;
Cosa intende esattamente?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dobbiamo modificare le nostre media query CSS per i dispositivi pieghevoli e i tablet?&lt;/li&gt;
&lt;li&gt;Oppure dobbiamo spezzare i task JavaScript lunghi per migliorare il nostro INP?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Stiamo usando la stessa identica parola per indicare sia &amp;quot;si adatta alle dimensioni dello schermo&amp;quot; che &amp;quot;reagisce velocemente agli input dell&#39;utente&amp;quot;.&lt;/p&gt;
&lt;p&gt;E questa confusione è destinata a crescere. Se parli con sviluppatori appena entrati nel settore, o se chiedi a un assistente di programmazione IA di &amp;quot;rendere questa UI più responsive&amp;quot;, cosa faranno in realtà? Inizieranno a scrivere regole &lt;code&gt;@media&lt;/code&gt; in CSS o apriranno i Chrome DevTools per profilare i tempi di blocco del thread principale (main thread)? Onestamente, entrambe le strade rappresentano un&#39;interpretazione valida della parola.&lt;/p&gt;
&lt;h2 id=&quot;una-proposta-dividere-la-terminologia&quot; tabindex=&quot;-1&quot;&gt;Una proposta: dividere la terminologia &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/should-we-stop-using-the-word-responsive-for-design/#una-proposta-dividere-la-terminologia&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Forse è giunto il momento di abbandonare la parola &amp;quot;responsive&amp;quot;, almeno quando parliamo di dimensioni dello schermo.&lt;/p&gt;
&lt;p&gt;E se iniziassimo a usare &lt;strong&gt;&amp;quot;adaptive&amp;quot;&lt;/strong&gt; per tutto ciò che riguarda l&#39;adattamento del layout (sia sul web che nelle app native), e riservassimo &lt;strong&gt;&amp;quot;responsive&amp;quot;&lt;/strong&gt; puramente alle performance web?&lt;/p&gt;
&lt;p&gt;Secondo questo modello:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Un sito o un&#39;app &lt;strong&gt;adaptive&lt;/strong&gt; (adattivo) adatta il proprio layout al viewport (mobile, desktop, pieghevole).&lt;/li&gt;
&lt;li&gt;Un sito o un&#39;app &lt;strong&gt;responsive&lt;/strong&gt; (reattivo) risponde velocemente alle interazioni dell&#39;utente (basso INP, nessun blocco del thread principale).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Per dirla in parole semplici, se dovessi spiegare questo concetto a mia madre, direi che un layout &lt;em&gt;si adatta&lt;/em&gt; alle dimensioni dello schermo, non che &amp;quot;risponde&amp;quot; ad esse. È un modo di descriverlo decisamente più naturale.&lt;/p&gt;
&lt;p&gt;Sembra più pulito, più logico e risolve la sovrapposizione terminologica. Ma la web community è pronta ad abbandonare la definizione del 2010 di Ethan Marcotte? O il &amp;quot;responsive design&amp;quot; è impresso troppo a fondo nei nostri cervelli?&lt;/p&gt;
&lt;p&gt;Sono curioso di sapere cosa ne pensi. Questa distinzione ha senso o è troppo tardi per cambiare? Scrivimi pure per &lt;a href=&quot;https://andreaverlicchi.eu/contact/&quot;&gt;farmi sapere cosa ne pensi&lt;/a&gt;!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Talk: &quot;Ehi Gemini, sistema il CSS!&quot; al CSS Day Bologna</title>
		<link href="https://andreaverlicchi.eu/it/blog/css-day-bologna-talk-chrome-devtools-agents/"/>
		<updated>2026-06-11T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/css-day-bologna-talk-chrome-devtools-agents/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/c9_tY4rLn0-648.webp 648w, https://andreaverlicchi.eu/img/c9_tY4rLn0-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/c9_tY4rLn0-648.png 648w, https://andreaverlicchi.eu/img/c9_tY4rLn0-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Ehi Gemini, sistema il CSS!&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/c9_tY4rLn0-648.png&quot; width=&quot;1296&quot; height=&quot;728&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Talk: &quot;Ehi Gemini, sistema il CSS!&quot; al CSS Day Bologna&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;time datetime=&quot;2026-06-11&quot;&gt;Giovedì 11 giugno 2026&lt;/time&gt;, ho avuto il piacere di tenere una presentazione alla conferenza &lt;a href=&quot;https://cssday.it/&quot;&gt;CSS Day&lt;/a&gt; a Bologna.&lt;/p&gt;
&lt;p&gt;Vi siete mai chiesti quanto tempo perdiamo ogni giorno a fare clic con il tasto destro su &amp;quot;Ispeziona&amp;quot;, cambiare la dimensione del viewport 50 volte o andare a caccia di quella singola regola CSS che sovrascrive i nostri stili? I tradizionali assistenti di programmazione IA sono eccezionali, ma sono &amp;quot;ciechi&amp;quot; rispetto all&#39;ambiente live del browser: non possono vedere il DOM in memoria, il traffico di rete o gli errori in console.&lt;/p&gt;
&lt;p&gt;In questo talk del CSS Day, esploriamo &lt;strong&gt;Chrome DevTools for Agents&lt;/strong&gt; (noto anche come DTA), uno strumento rilasciato in versione 1.0 a maggio durante il Google I/O. Grazie al &lt;strong&gt;Model Context Protocol&lt;/strong&gt; (MCP), questo tool espone le funzionalità native di DevTools direttamente agli agenti IA (come Gemini, Claude Code, Cursor o Antigravity).&lt;/p&gt;
&lt;p&gt;Il risultato? L&#39;IA può navigare, ispezionare fogli di stile, compilare moduli ed eseguire un vero e proprio debugging per nostro conto.&lt;/p&gt;
&lt;h2 id=&quot;guarda-il-video&quot; tabindex=&quot;-1&quot;&gt;Guarda il video &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/css-day-bologna-talk-chrome-devtools-agents/#guarda-il-video&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/Ol2Xo29Z3tE&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; referrerpolicy=&quot;strict-origin-when-cross-origin&quot; allowfullscreen=&quot;&quot; loading=&quot;lazy&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;h2 id=&quot;slide&quot; tabindex=&quot;-1&quot;&gt;Slide &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/css-day-bologna-talk-chrome-devtools-agents/#slide&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Puoi scaricare o visualizzare le slide della presentazione qui:
&lt;a href=&quot;https://andreaverlicchi.eu/pdf/ehi-gemini-sistema-il-css-chrome-devtools-for-agents-css-day-2026.pdf&quot;&gt;🔗 Scarica le slide della presentazione (PDF)&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Google Antigravity 2 &amp; Gemini 3.5 Flash: questa accoppiata IA ha cambiato il mio flusso di sviluppo... di nuovo</title>
		<link href="https://andreaverlicchi.eu/it/blog/google-antigravity-2-gemini-35-flash/"/>
		<updated>2026-05-22T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/google-antigravity-2-gemini-35-flash/</id>
		<content type="html">&lt;p&gt;Sono passati solo pochi giorni da quando ho iniziato a usarlo, ma sono già incredibilmente entusiasta. La velocità, la precisione, il processo di pianificazione e i risultati finali ottenuti sono semplicemente eccezionali.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/IzZVtZKqba-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Il logo di Google Antigravity con il testo &#39;Experience liftoff&#39;.&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/IzZVtZKqba-648.png&quot; width=&quot;648&quot; height=&quot;367&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Google Antigravity 2 è arrivato, ed è una svolta totale.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Facciamo un passo indietro. Antigravity 1 era essenzialmente una shell di VS Code con una chat integrata. Sembrava molto simile alla combinazione VS Code + Copilot, ma con un tocco estremamente interessante: la &lt;strong&gt;Planning Mode&lt;/strong&gt; (Modalità di Pianificazione). Prima di eseguire qualsiasi modifica, la chat si metteva in pausa, rifletteva su ciò che aveva capito, mostrava un piano di implementazione dettagliato passo dopo passo e chiedeva una conferma esplicita. Era molto simile alla modalità di pianificazione di Claude, ma confezionata in un&#39;interfaccia utente molto più pulita, facile da leggere e commentabile.&lt;/p&gt;
&lt;p&gt;Con &lt;strong&gt;Antigravity 2&lt;/strong&gt;, hanno fatto un passo audace. Hanno rimosso completamente la modalità editor di codice (o l&#39;hanno nascosta così bene che non l&#39;ho ancora trovata!). Al suo posto, c&#39;è un&#39;interfaccia di chat pura e priva di distrazioni, focalizzata interamente sul flusso di lavoro agentico, mantenendo del tutto intatta quella meravigliosa e comoda Planning Mode della versione 1.&lt;/p&gt;
&lt;h2 id=&quot;flussi-di-lavoro-multi-progetto-senza-interruzioni&quot; tabindex=&quot;-1&quot;&gt;Flussi di lavoro multi-progetto senza interruzioni &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-antigravity-2-gemini-35-flash/#flussi-di-lavoro-multi-progetto-senza-interruzioni&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ciò che rende Antigravity 2 così potente è il modo in cui opera in background:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Supporto multi-progetto&lt;/strong&gt;: Funziona perfettamente su tutti i progetti attivi nel tuo workspace.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chat parallele&lt;/strong&gt;: Ogni progetto può avere più chat concorrenti in esecuzione in parallelo.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Git Worktree&lt;/strong&gt;: Ogni chat indipendente può essere eseguita direttamente sul tuo branch locale o all&#39;interno del proprio Git worktree dedicato, consentendo all&#39;agente di scrivere codice ed eseguire build in isolamento senza bloccare il tuo tree di lavoro principale.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Consiglio di usarlo affiancato al tuo IDE tradicional preferito. Nel mio lavoro quotidiano, passo costantemente da Antigravity 2 a &lt;strong&gt;JetBrains PyCharm&lt;/strong&gt;. Uso Antigravity per eseguire i compiti degli agenti, pianificare il refactoring e modificare il codice, e poi passo a PyCharm per avviare, testare e gestire tutto il resto proprio come facevo prima. È lo spazio di lavoro ibrido perfetto.&lt;/p&gt;
&lt;h2 id=&quot;sotto-il-cofano-gemini-3-5-flash-e-una-bomba&quot; tabindex=&quot;-1&quot;&gt;Sotto il cofano: Gemini 3.5 Flash è una bomba &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-antigravity-2-gemini-35-flash/#sotto-il-cofano-gemini-3-5-flash-e-una-bomba&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Antigravity 2 supporta sia Gemini 3.5 che Claude. Se hai un account Google, ottieni un generoso piano gratuito di Gemini 3.5 incluso fin da subito, che consiglio vivamente di provare. Se preferisci Claude, puoi semplicemente collegare il tuo account Anthropic e partire.&lt;/p&gt;
&lt;p&gt;Personalmente ho testato quasi tutti i principali modelli in circolazione — da o3 di OpenAI, a Gemini 2.5 Pro, fino a Claude Sonnet 3.7 e Opus 4.6. Nel tempo, ho costantemente finito per apprezzare maggiormente la qualità e la pertinenza delle risposte di Gemini.&lt;/p&gt;
&lt;p&gt;E &lt;strong&gt;Gemini 3.5 Flash&lt;/strong&gt;? È una bomba assoluta (&lt;em&gt;una bomba&lt;/em&gt;, come diciamo in Italia). È incredibilmente veloce, estremamente preciso e decisamente intelligente. Devi provarlo di persona per capire la differenza di velocità.&lt;/p&gt;
&lt;h2 id=&quot;cosa-stai-aspettando&quot; tabindex=&quot;-1&quot;&gt;Cosa stai aspettando? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-antigravity-2-gemini-35-flash/#cosa-stai-aspettando&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Nel tempo necessario a finire di leggere questo paragrafo, avresti già potuto &lt;a href=&quot;https://antigravity.google/download&quot;&gt;scaricarlo&lt;/a&gt;. E nel tempo che impiegheresti a scrivere una risposta a questo post, potresti scrivere il tuo primo prompt e provarlo in prima persona.&lt;/p&gt;
&lt;p&gt;Se sei uno sviluppatore che vuole dare una spinta alla propria produttività, prova l&#39;accoppiata Antigravity 2 e Gemini 3.5 Flash. Penso proprio che non tornerai indietro. 😊&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Il mio sogno di un formato d&#39;immagine contenitore: un appello alla web community</title>
		<link href="https://andreaverlicchi.eu/it/blog/end-of-responsive-images-dream-image-format/"/>
		<updated>2026-04-29T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/end-of-responsive-images-dream-image-format/</id>
		<content type="html">&lt;p&gt;Qualche giorno fa, &lt;a href=&quot;https://piccalil.li/author/mat-marquis/&quot;&gt;Mat Marquis&lt;/a&gt; ha scritto un ottimo articolo sulla &lt;a href=&quot;https://piccalil.li/blog/the-end-of-responsive-images/#the-beginning-and-the-end&quot;&gt;fine delle immagini responsive&lt;/a&gt;, spiegando come l&#39;attributo &lt;code&gt;sizes=&amp;quot;auto&amp;quot;&lt;/code&gt;, ormai ampiamente supportato, consenta ai browser di calcolare autonomamente le dimensioni di rendering delle immagini caricate in modalità lazy, eliminando la necessità di creare manualmente l&#39;attributo &lt;code&gt;sizes&lt;/code&gt; per la maggior parte delle immagini.&lt;/p&gt;
&lt;p&gt;Leggerlo ha risvegliato un sogno che porto con me da anni: un formato di immagine che ci permetterebbe di scrivere un tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; radicalmente più semplice — persino più semplice di quanto consenta &lt;code&gt;sizes=&amp;quot;auto&amp;quot;&lt;/code&gt;. Ci arriverò più in basso. Ma prima, un rapido riassunto del pezzo di Andy per il contesto.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Vf5NuI4bBl-648.webp 648w, https://andreaverlicchi.eu/img/Vf5NuI4bBl-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/Vf5NuI4bBl-648.png 648w, https://andreaverlicchi.eu/img/Vf5NuI4bBl-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;A sinistra, il testo &#39;The dream of a container image format&#39;. A destra, una rappresentazione grafica di un&#39;immagine contenitore con estensione &#39;.img&#39; che raggruppa al suo interno diverse dimensioni dell&#39;immagine.&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/Vf5NuI4bBl-648.png&quot; width=&quot;1296&quot; height=&quot;723&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Un formato di immagine ideale: un solo file, tutte le dimensioni necessarie.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;il-tl-dr-di-andy&quot; tabindex=&quot;-1&quot;&gt;Il TL;DR di Andy &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/end-of-responsive-images-dream-image-format/#il-tl-dr-di-andy&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Per le immagini caricate in modalità lazy (la maggior parte delle immagini su una pagina), possiamo abbandonare la scrittura manuale di &lt;code&gt;sizes&lt;/code&gt; e lasciare che sia il browser a fare il lavoro:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;loading&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;auto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
    shirt_300w.jpg   300w,
    shirt_600w.jpg   600w,
    shirt_1200w.jpg 1200w,
    shirt_2400w.jpg 2400w
  &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;A shirt&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Per le immagini &amp;quot;hero&amp;quot; — quelle above the fold, candidate a diventare LCP della pagina — dobbiamo ancora essere meticolosi con il dimensionamento preventivo tramite &lt;code&gt;sizes&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;loading&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;eager&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
    shirt_300w.jpg   300w,
    shirt_600w.jpg   600w,
    shirt_1200w.jpg 1200w,
    shirt_2400w.jpg 2400w
  &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: 1200px) 100vw,
         (min-width: 600px) 600px,
         300px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;A shirt&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quindi &lt;code&gt;sizes&lt;/code&gt; può per lo più sparire. Ma ci rimane comunque quel lungo &lt;code&gt;srcset&lt;/code&gt; che elenca ogni variante. Ed è qui che ritorna il mio vecchio sogno.&lt;/p&gt;
&lt;h2 id=&quot;ho-un-sogno&quot; tabindex=&quot;-1&quot;&gt;Ho un sogno &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/end-of-responsive-images-dream-image-format/#ho-un-sogno&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Da anni sogno un formato di immagine contenitore — un singolo file che contenga al suo interno ogni risoluzione di un&#39;immagine. Immaginatelo come una cartella di immagini compressa, confezionata come un unico file.&lt;/p&gt;
&lt;p&gt;Con un formato simile, il tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;, almeno per le immagini lazy, potrebbe essere drasticamente semplificato. Qualcosa del genere:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;shirt.imgc *w&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;auto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;loading&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;A shirt&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Niente più &lt;code&gt;srcset&lt;/code&gt; complessi con elenchi di larghezze separati da virgole. Il browser aprirebbe il file, vedrebbe quali risoluzioni sono disponibili all&#39;interno e scaricherebbe solo i byte necessari per la dimensione che deve renderizzare.&lt;/p&gt;
&lt;p&gt;Il tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;, finalmente di nuovo semplice.&lt;/p&gt;
&lt;h2 id=&quot;un-appello-alla-community&quot; tabindex=&quot;-1&quot;&gt;Un appello alla community &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/end-of-responsive-images-dream-image-format/#un-appello-alla-community&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;L&#39;articolo di Andy dimostra che la piattaforma può assorbire gran parte della complessità che ci portiamo dietro nel nostro markup. Mi piacerebbe vederci andare ancora oltre.&lt;/p&gt;
&lt;p&gt;A chi si occupa di standard web, agli autori dei formati di immagine e agli ingegneri dei browser che stanno leggendo: un formato di immagine contenitore è qualcosa che potremmo effettivamente realizzare? Le richieste HTTP range consentono già ai browser di recuperare segmenti di file. I formati contenitore esistono già in altri ambiti. I mattoni fondamentali sono tutti lì.&lt;/p&gt;
&lt;p&gt;Custodisco questo sogno da molto tempo. Potremmo finalmente renderlo realtà?&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Talk: Migliorare la reattività del web al Web Day 2026, Milano</title>
		<link href="https://andreaverlicchi.eu/it/blog/web-day-2026-enhancing-web-responsiveness/"/>
		<updated>2026-04-01T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/web-day-2026-enhancing-web-responsiveness/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/niFQg6TlTD-648.webp 648w, https://andreaverlicchi.eu/img/niFQg6TlTD-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/niFQg6TlTD-648.jpeg 648w, https://andreaverlicchi.eu/img/niFQg6TlTD-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi sul palco del Web Day 2026, Milano&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/niFQg6TlTD-648.jpeg&quot; width=&quot;1296&quot; height=&quot;864&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Andrea Verlicchi sul palco del Web Day 2026, Milano&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Ho avuto l&#39;opportunità di parlare al &lt;a href=&quot;https://www.webdayconf.it/&quot;&gt;Web Day 2026&lt;/a&gt;, la nona edizione della conferenza organizzata da Improove a Milano, tenutasi il &lt;time datetime=&quot;2026-03-30&quot;&gt;30 marzo 2026&lt;/time&gt; presso il Talent Garden Calabiana.&lt;/p&gt;
&lt;p&gt;Il mio talk si intitolava &amp;quot;Enhancing Web Responsiveness — A practical guide to debugging and avoiding slow interactions&amp;quot; (Migliorare la reattività del web — Una guida pratica al debugging ed evitare le interazioni lente), incentrato su Interaction to Next Paint (INP), la metrica dei Core Web Vitals che misura quanto una pagina sia reattiva alle interazioni degli utenti.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/pBs26H3_Ty-648.webp 648w, https://andreaverlicchi.eu/img/pBs26H3_Ty-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/pBs26H3_Ty-648.jpeg 648w, https://andreaverlicchi.eu/img/pBs26H3_Ty-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi sul palco del Web Day 2026, Milano&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/pBs26H3_Ty-648.jpeg&quot; width=&quot;1296&quot; height=&quot;864&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Andrea Verlicchi sul palco del Web Day 2026, Milano&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Ho condiviso casi di studio reali mostrando come identificare e risolvere una scarsa metrica INP, insieme a tecniche pratiche da applicare fin da subito per rendere i vostri siti web più scattanti. Se vi siete mai chiesti perché il clic su un pulsante sembri lento o un modulo impieghi un&#39;eternità a rispondere, questo talk faceva al caso vostro.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.webdayconf.it/e/sessione/5113/Enhancing-Web-Responsiveness-%E2%80%93-A-practical-guide-to-debugging-and-avoiding-slow-interactions&quot;&gt;🔗 Pagina del talk sul sito del Web Day&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Rifattorizziamo i bias di genere, un commit alla volta</title>
		<link href="https://andreaverlicchi.eu/it/blog/refactoring-gender-bias-one-commit-at-a-time/"/>
		<updated>2026-03-27T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/refactoring-gender-bias-one-commit-at-a-time/</id>
		<content type="html">&lt;p&gt;Recentemente ho avuto il piacere di co-presentare un talk con &lt;a href=&quot;https://www.linkedin.com/in/giulia-naponiello/&quot;&gt;Giulia Naponiello&lt;/a&gt;, Senior Software Engineer presso Red Hat, riguardo ai bias di genere nel settore tecnologico in due meetup locali. Il talk, intitolato &amp;quot;Rifattorizziamo i bias di genere, un commit alla volta&amp;quot;, ha esplorato come i bias inconsci si manifestino in modo sottile negli ambienti di lavoro tech.&lt;/p&gt;
&lt;p&gt;Abbiamo condiviso storie personali ed esaminato come i bias si presentino nelle situazioni quotidiane — dal linguaggio usato nelle code review alle valutazioni durante i colloqui di assunzione, dal riconoscimento dell&#39;autorità tecnica alle dinamiche di team. L&#39;obiettivo non era puntare il dito, ma fare luce sui &amp;quot;bug culturali&amp;quot; che tutti noi portiamo con noi e suggerire modi per risolverli. Pensatelo come un refactoring: stessa base di codice, risultati migliori. 🐛➡️✅&lt;/p&gt;
&lt;h2 id=&quot;bologna-front-end&quot; tabindex=&quot;-1&quot;&gt;Bologna Front-end 🇮🇹 &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/refactoring-gender-bias-one-commit-at-a-time/#bologna-front-end&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Bxmbrmmo2p-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Rifattorizziamo i bias di genere, un commit alla volta - DevRomagna, marzo 2026 - Giulia Naponiello e Andrea Verlicchi&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/Bxmbrmmo2p-648.png&quot; width=&quot;648&quot; height=&quot;364&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;La slide di copertina del nostro talk.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;time datetime=&quot;2026-03-10&quot;&gt;Martedì 10 marzo 2026&lt;/time&gt;, abbiamo presentato al 61° episodio di &lt;a href=&quot;https://www.meetup.com/it-IT/bologna-front-end/&quot;&gt;Bologna Front-end&lt;/a&gt; presso Granata a Bologna.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/8tXGJk0Q1fs&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; referrerpolicy=&quot;strict-origin-when-cross-origin&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot; loading=&quot;lazy&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;a href=&quot;https://www.meetup.com/it-it/bologna-front-end/events/313066751/&quot;&gt;🔗 Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;devromagna&quot; tabindex=&quot;-1&quot;&gt;DevRomagna 🇮🇹 &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/refactoring-gender-bias-one-commit-at-a-time/#devromagna&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;time datetime=&quot;2026-03-17&quot;&gt;Martedì 17 marzo 2026&lt;/time&gt;, abbiamo portato lo stesso talk a &lt;a href=&quot;https://www.meetup.com/it-IT/devromagna/&quot;&gt;DevRomagna&lt;/a&gt; presso Gellify a Imola.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.meetup.com/it-it/devromagna/events/313450456/&quot;&gt;🔗 Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>GitBar Podcast: Non toccate quel tag!</title>
		<link href="https://andreaverlicchi.eu/it/blog/gitbar-podcast-web-performance/"/>
		<updated>2026-03-19T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/gitbar-podcast-web-performance/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/pc_qdd2vex-648.webp 648w, https://andreaverlicchi.eu/img/pc_qdd2vex-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/pc_qdd2vex-648.png 648w, https://andreaverlicchi.eu/img/pc_qdd2vex-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;GitBar Podcast episodio 228 - Non toccate quel tag! con Andrea Verlicchi&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/pc_qdd2vex-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;GitBar Podcast - Episodio 228&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Recentemente ho avuto il piacere di essere ospite di &lt;a href=&quot;https://www.gitbar.it/&quot;&gt;GitBar&lt;/a&gt;, il podcast italiano condotto da Mauro &amp;quot;Brainrepo&amp;quot; Murru. Nell&#39;episodio 228, intitolato &amp;quot;Non toccate quel tag!&amp;quot;, abbiamo fatto una lunga e divertente chiacchierata sulle web performance — dai Core Web Vitals all&#39;ottimizzazione delle immagini, dal famigerato Interaction to Next Paint ai danni silenziosi del Google Tag Manager.&lt;/p&gt;
&lt;p&gt;Abbiamo anche toccato alcuni argomenti nostalgici come Flash, Dreamweaver e MySpace, e parlato di come strumenti di IA come Claude stiano iniziando ad aiutare nell&#39;analisi delle performance. È stato davvero divertente!&lt;/p&gt;
&lt;h2 id=&quot;guarda-ascolta&quot; tabindex=&quot;-1&quot;&gt;Guarda / Ascolta &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/gitbar-podcast-web-performance/#guarda-ascolta&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/YXuWrBe6zyU&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen=&quot;&quot; loading=&quot;lazy&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Puoi trovare l&#39;episodio anche sul &lt;a href=&quot;https://www.gitbar.it/episode/ep228-non-toccate-quel-tag-con-andrea-verlicchi&quot;&gt;sito di GitBar&lt;/a&gt;.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Talk: Gemini + Chrome: Oltre la Chat, Bologna JS Meetup</title>
		<link href="https://andreaverlicchi.eu/it/blog/bologna-js-gemini-chrome-devtools-mcp/"/>
		<updated>2026-02-25T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/bologna-js-gemini-chrome-devtools-mcp/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/qS--BYanGM-648.webp 648w, https://andreaverlicchi.eu/img/qS--BYanGM-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;undefined&quot; srcset=&quot;https://andreaverlicchi.eu/img/qS--BYanGM-648.heif 648w, https://andreaverlicchi.eu/img/qS--BYanGM-1296.heif 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Bologna JS Meetup - Gemini + Chrome: Oltre la Chat. Usare l&#39;AI per controllare il browser&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/qS--BYanGM-648.webp&quot; width=&quot;1296&quot; height=&quot;728&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Bologna JS Meetup&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;time datetime=&quot;2026-02-25&quot;&gt;Mercoledì 25 febbraio 2026&lt;/time&gt;, ho tenuto una presentazione al &lt;a href=&quot;https://www.meetup.com/bologna-js-meetup/&quot;&gt;Bologna JS Meetup&lt;/a&gt; presso Spazio01 Coworking a Bologna.&lt;/p&gt;
&lt;p&gt;Il talk, dal titolo &amp;quot;Gemini + Chrome: Oltre la Chat. Usare l&#39;AI per controllare il browser&amp;quot;, è stato una demo del &lt;a href=&quot;https://github.com/ChromeDevTools/chrome-devtools-mcp&quot;&gt;Chrome DevTools MCP Server&lt;/a&gt; — mostrando come connettere l&#39;IA a Chrome DevTools attraverso il &lt;a href=&quot;https://modelcontextprotocol.io/&quot;&gt;Model Context Protocol&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Ho mostrato esempi pratici di come:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Leggere il DOM in tempo reale e manipolare le pagine web&lt;/li&gt;
&lt;li&gt;Eseguire smoke test visivi su diversi viewport&lt;/li&gt;
&lt;li&gt;Simulare interazioni utente complesse per test end-to-end&lt;/li&gt;
&lt;li&gt;Intercettare richieste di rete e analizzare metriche di performance&lt;/li&gt;
&lt;li&gt;Identificare colli di bottiglia nelle prestazioni&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;https://www.meetup.com/bologna-js-meetup/events/313427486/&quot;&gt;🔗 Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Video del talk: &quot;Ehi Gemini, sistema il CSS!&quot;, Bologna Front-end #58</title>
		<link href="https://andreaverlicchi.eu/it/blog/bologna-front-end-gemini-chrome-devtools-mcp/"/>
		<updated>2025-12-09T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/bologna-front-end-gemini-chrome-devtools-mcp/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/qBSIBBiQMA-648.webp 648w, https://andreaverlicchi.eu/img/qBSIBBiQMA-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;undefined&quot; srcset=&quot;https://andreaverlicchi.eu/img/qBSIBBiQMA-648.heif 648w, https://andreaverlicchi.eu/img/qBSIBBiQMA-1296.heif 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Meetup Bologna Front-end episodio 58 - Ehi Gemini, sistema il CSS! con Andrea Verlicchi&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/qBSIBBiQMA-648.webp&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Bologna Front-end #58&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;time datetime=&quot;2025-12-09&quot;&gt;Martedì 9 dicembre 2025&lt;/time&gt;, ho tenuto una presentazione durante il 58° episodio di &lt;a href=&quot;https://www.meetup.com/bologna-front-end/&quot;&gt;Bologna Front-end&lt;/a&gt; presso Granata a Bologna.&lt;/p&gt;
&lt;p&gt;Il talk, dal titolo &amp;quot;Ehi Gemini, sistema il CSS!&amp;quot;, è stato una demo live del &lt;a href=&quot;https://github.com/ChromeDevTools/chrome-devtools-mcp&quot;&gt;Chrome DevTools MCP Server&lt;/a&gt; — uno strumento che permette di controllare Chrome DevTools attraverso il &lt;a href=&quot;https://modelcontextprotocol.io/&quot;&gt;Model Context Protocol&lt;/a&gt; (MCP), utilizzando comandi in linguaggio naturale direttamente dal terminale.&lt;/p&gt;
&lt;p&gt;Ho mostrato come sfruttarlo per:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Eseguire audit di accessibilità&lt;/li&gt;
&lt;li&gt;Effettuare il debug di layout CSS complessi&lt;/li&gt;
&lt;li&gt;Simulare diverse condizioni di rete&lt;/li&gt;
&lt;li&gt;Testare viewport personalizzati per il responsive design&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tutto attraverso il linguaggio naturale, senza mai lasciare il terminale. Davvero notevole!&lt;/p&gt;
&lt;h2 id=&quot;guarda-il-video&quot; tabindex=&quot;-1&quot;&gt;Guarda il video &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/bologna-front-end-gemini-chrome-devtools-mcp/#guarda-il-video&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/sCHuoalAJCs&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen=&quot;&quot; loading=&quot;lazy&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;a href=&quot;https://www.meetup.com/bologna-front-end/events/312180052/&quot;&gt;🔗 Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Google Antigravity: il nuovo IDE che abbraccia l&#39;IA agentica</title>
		<link href="https://andreaverlicchi.eu/it/blog/google-antigravity-new-ide-agentic-ai/"/>
		<updated>2025-11-24T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/google-antigravity-new-ide-agentic-ai/</id>
		<content type="html">&lt;p&gt;C&#39;è un nuovo IDE di Google che abbraccia l&#39;IA agentica e sfrutta Gemini 3: &lt;a href=&quot;https://antigravity.google/&quot;&gt;Google Antigravity&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/7qVgD3KN79-648.webp 648w, https://andreaverlicchi.eu/img/7qVgD3KN79-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/7qVgD3KN79-648.png 648w, https://andreaverlicchi.eu/img/7qVgD3KN79-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Una rappresentazione astratta, luminosa e futuristica dell&#39;interfaccia dell&#39;IDE Google Antigravity.&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/7qVgD3KN79-648.png&quot; width=&quot;1296&quot; height=&quot;695&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;p&gt;Grazie al ragionamento avanzato, alla gestione degli strumenti e alle capacità di programmazione autonoma di Gemini 3, Google Antigravity trasforma l&#39;assistenza dell&#39;IA da semplice strumento nella cassetta degli attrezzi di uno sviluppatore a un partner attivo. Sebbene il cuore di Google Antigravity sia una familiare esperienza di IDE con IA, i suoi agenti sono stati elevati a un&#39;interfaccia dedicata e hanno ottenuto l&#39;accesso diretto all&#39;editor, al terminale e al browser. Ora gli agenti possono pianificare ed eseguire autonomamente compiti software complessi ed end-to-end per tuo conto, convalidando al contempo il proprio codice.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/SVCBA-pBgt0?si=-KPiJ6v2sxRXdude&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Venerdì, io e il mio collega Brian lo abbiamo messo all&#39;opera su un compito complesso nello sviluppo del progetto a cui stiamo lavorando, con il modello Gemini 3, e ne siamo rimasti piuttosto colpiti.&lt;/p&gt;
&lt;p&gt;Ciò che amo di Antigravity è che gestisce la pianificazione producendo due artefatti testuali, proprio come farebbe un Tech Lead: un &lt;strong&gt;Walkthrough&lt;/strong&gt; (panoramica) e i &lt;strong&gt;Tasks&lt;/strong&gt; (compiti). Puoi fornire feedback su questi — sia che abbia commesso un errore, sia che il prompt non fosse abbastanza specifico — selezionando il testo e commentandolo, in modo simile a come faresti in Google Docs o Notion. Puoi anche dare un feedback sull&#39;intero approccio, un po&#39; come in una Pull Request. Io ci scrivo quasi sempre &amp;quot;LGTM&amp;quot; (Looks Good To Me). Dopodiché inizia a lavorare. In realtà, ultimamente, inizia a lavorare persino prima del tuo feedback per portarsi avanti, fiducioso del suo piano, potendo poi correggere la rotta in seguito se necessario.&lt;/p&gt;
&lt;p&gt;Ho provato a lavorare senza Antigravity, usando solo OpenSpec con Gemini 3 tramite la &lt;code&gt;gemini-cli&lt;/code&gt;, ma l&#39;ho trovato più macchinoso e frustrante. La CLI non è asincrona come Antigravity, quindi si perde un sacco di tempo ad aspettare che l&#39;IA pensi. Antigravity suddivide tutto in compiti più piccoli, che sono più facili e veloci da gestire per l&#39;IA, perciò inizia a lavorare prima e finisce più in fretta.&lt;/p&gt;
&lt;p&gt;Poi c&#39;è l&#39;&lt;strong&gt;Agent Manager&lt;/strong&gt;. Se ti va di fare lo sviluppatore supereroe potenziato dall&#39;IA, puoi chiedergli di fare diverse cose in parallelo, anche su repository differenti (o su cloni diversi dello stesso repository se hai bisogno di lavorare su due rami diversi).&lt;/p&gt;
&lt;p&gt;Volevo saperne di più su come usarlo al meglio, così questo fine settimana ho dedicato del tempo a guardare un paio di video che consiglio caldamente.&lt;/p&gt;
&lt;h2 id=&quot;imparare-le-basi-di-google-antigravity&quot; tabindex=&quot;-1&quot;&gt;Imparare le basi di Google Antigravity &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-antigravity-new-ide-agentic-ai/#imparare-le-basi-di-google-antigravity&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il primo è &amp;quot;Learn the basics of Google Antigravity&amp;quot; del team di Antigravity.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/nTOVIGsqCuY?si=Q74TZpCHCD14C2EY&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Questo video fornisce un&#39;introduzione ufficiale e una panoramica dei componenti principali di Antigravity:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Tre superfici principali&lt;/strong&gt;: Lo strumento combina un &lt;strong&gt;Agent Manager&lt;/strong&gt; (per creare e gestire gli agenti), un &lt;strong&gt;Editor&lt;/strong&gt; (un&#39;esperienza IDE completa) e un &lt;strong&gt;Browser&lt;/strong&gt; (che integra un agente direttamente all&#39;interno di Chrome per i test autonomi).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sviluppo assistito da agenti&lt;/strong&gt;: L&#39;LLM è impostato per prendere decisioni e implementare compiti semplici in modo automatico. Per problemi complessi, può mettersi in pausa e chiedere chiarimenti all&#39;utente.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Artefatti per la trasparenza&lt;/strong&gt;: L&#39;agente genera file markdown come &lt;strong&gt;Piani di implementazione&lt;/strong&gt; e &lt;strong&gt;Panoramiche&lt;/strong&gt; per documentare i suoi progressi e le modifiche apportate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Esecuzione parallela dei task&lt;/strong&gt;: Gli sviluppatori possono avviare un compito per l&#39;agente e iniziarne un altro complesso in autonomia.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test autonomi&lt;/strong&gt;: L&#39;agente può avviare il browser integrato per verificare le proprie modifiche al codice.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;google-antigravity-il-nuovo-miglior-editor-di-ia&quot; tabindex=&quot;-1&quot;&gt;Google Antigravity: il nuovo miglior editor di IA? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-antigravity-new-ide-agentic-ai/#google-antigravity-il-nuovo-miglior-editor-di-ia&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se vuoi una visione più approfondita, dai un&#39;occhiata a &amp;quot;Google Antigravity: The New Best AI Editor?&amp;quot; di &amp;quot;AI with Brandon&amp;quot;.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/j0UPItO6BX4?si=Nlfsk8KXBsgRcG2J&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Questa recensione evidenzia:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Casella di posta dell&#39;Agent Manager&lt;/strong&gt;: L&#39;interfaccia principale è progettata come una casella di posta elettronica per gestire più progetti.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accesso gratuito a Gemini 3 Pro&lt;/strong&gt;: Include l&#39;accesso gratuito a Gemini 3 Pro all&#39;interno dell&#39;editor.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gestione di compiti complessi&lt;/strong&gt;: Il recensore mostra come l&#39;agente implementi con successo una funzionalità full-stack che coinvolge molteplici servizi esterni (trigger.dev, OpenAI TTS, blob store, database e aggiornamenti dell&#39;interfaccia utente).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sembra che cambierà il modo in cui sviluppiamo, trasformandoci in... orchestratori di agenti?&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Migliorare la reattività del web - Ottimizzazioni dell&#39;interattività da casi reali</title>
		<link href="https://andreaverlicchi.eu/it/blog/improving-web-responsiveness-interactivity-improvements-from-real-world-cases/"/>
		<updated>2025-11-01T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/improving-web-responsiveness-interactivity-improvements-from-real-world-cases/</id>
		<content type="html">&lt;p&gt;&lt;time datetime=&quot;2025-10-29&quot;&gt;Mercoledì 29 ottobre 2025&lt;/time&gt;, ho avuto il piacere di parlare all&#39;evento &lt;a href=&quot;https://luma.com/ziykhh4y&quot;&gt;performance.sync()&lt;/a&gt; ad Amsterdam. È stato un meetup pre-conferenza per la conferenza &lt;a href=&quot;https://perfnow.nl/&quot;&gt;performance.now()&lt;/a&gt;, e una fantastica opportunità per incontrare e imparare da altri esperti di web performance.&lt;/p&gt;
&lt;p&gt;Il mio talk, &amp;quot;Improving Web Responsiveness - Interactivity improvements from real-world cases&amp;quot; (Migliorare la reattività del web - Ottimizzazioni dell&#39;interattività da casi reali), è stata una sessione di 15 minuti in cui ho condiviso tecniche pratiche per il debugging e l&#39;ottimizzazione delle interazioni lente sui siti web.&lt;/p&gt;
&lt;p&gt;La velocità di interazione è un aspetto chiave della reattività di un sito alle interazioni dell&#39;utente. Questo talk mostra tecniche pratiche per migliorare le interazioni lente attraverso casi di studio reali di debugging e ottimizzazione di una scarsa velocità di interazione.&lt;/p&gt;
&lt;p&gt;Guarda il video del talk se vuoi capire come identificare, risolvere e correggere le interazioni lente, garantendo un&#39;esperienza utente costantemente reattiva.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/HSLLBUXuu08&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Le slide sono disponibili al seguente link.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://docs.google.com/presentation/d/1yrjOQV4CVB7AsA1onIj-QLALe4pG71YI3EHasEd5KCQ/edit?usp=sharing&quot;&gt;📽️ Slide&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Ed ecco una foto di me sul palco, giusto per fornire a Eleventy un&#39;immagine per l&#39;elenco dei post. 😉&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Gjh5wPI1Ul-648.webp 648w, https://andreaverlicchi.eu/img/Gjh5wPI1Ul-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/Gjh5wPI1Ul-648.jpeg 648w, https://andreaverlicchi.eu/img/Gjh5wPI1Ul-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi con un maglione giallo parla sul palco al meetup performance.sync() ad Amsterdam. La slide attuale mostra &amp;quot;Slow GTM Code. Audit. Remove. Update. Not enough?&amp;quot;&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/Gjh5wPI1Ul-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Sul palco di performance.sync() 2025.&lt;/figcaption&gt;
&lt;/figure&gt;
</content>
	</entry>
	
	<entry>
		<title>Il gestore degli appunti di macOS che stavi aspettando, ora nativo in macOS 26 Tahoe</title>
		<link href="https://andreaverlicchi.eu/it/blog/how-to-use-multiple-clipboard-feature-on-macOS-26-tahoe/"/>
		<updated>2025-09-16T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/how-to-use-multiple-clipboard-feature-on-macOS-26-tahoe/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/xjOsbWNCeV-509.webp 509w, https://andreaverlicchi.eu/img/xjOsbWNCeV-1018.webp 1018w&quot; sizes=&quot;509px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/xjOsbWNCeV-509.png 509w, https://andreaverlicchi.eu/img/xjOsbWNCeV-1018.png 1018w&quot; sizes=&quot;509px&quot;&gt;&lt;img alt=&quot;Overlay di Spotlight che mostra il titolo &#39;Clipboard&#39; e – nella cronologia – diversi elementi di testo, codice e immagini&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/xjOsbWNCeV-509.png&quot; width=&quot;1018&quot; height=&quot;759&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Uno screenshot dell&#39;overlay di Spotlight che mostra la cronologia degli appunti (ricercabile).&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Hai presente quando copi un pezzo di codice, poi ne copi un altro e perdi quello precedente? O quando sai di avere qualcosa negli appunti, vorresti copiare qualcos&#39;altro, ma devi prima incollare quello che hai negli appunti altrimenti lo perderai? Niente più stress da appunti. Finalmente gli appunti multipli sono arrivati su macOS 26 Tahoe.&lt;/p&gt;
&lt;p&gt;Con il rilascio di macOS Tahoe, non dovrai più affidarti ad app di terze parti per accedere agli elementi copiati in passato. È una svolta per chiunque copi e incolli regolarmente più porzioni di testo (inclusi blocchi di codice), link o immagini.&lt;/p&gt;
&lt;p&gt;Ecco una guida rapida su come iniziare a usare questa attesissima funzionalità e velocizzare il tuo flusso di lavoro.&lt;/p&gt;
&lt;h3 id=&quot;abilitare-la-cronologia-degli-appunti&quot; tabindex=&quot;-1&quot;&gt;Abilitare la cronologia degli appunti &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-use-multiple-clipboard-feature-on-macOS-26-tahoe/#abilitare-la-cronologia-degli-appunti&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;La cronologia degli appunti è integrata direttamente in Spotlight, ma non è visibile da subito. Al primo utilizzo, dovrai abilitarla. Ecco come:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Premi &lt;code&gt;Command (⌘)&lt;/code&gt; + &lt;code&gt;Spazio&lt;/code&gt; per aprire Spotlight.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ora hai due opzioni per accedere alle nuove funzioni degli appunti:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Premi il tasto &lt;code&gt;Tab&lt;/code&gt; per rivelare i nuovi menu di Spotlight.&lt;/li&gt;
&lt;li&gt;Premi &lt;code&gt;Command (⌘)&lt;/code&gt; + &lt;code&gt;4&lt;/code&gt; per andare direttamente alla scheda &lt;strong&gt;Clipboard&lt;/strong&gt; (Appunti).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;La prima volta che lo fai, apparirà un avviso che ti chiederà di abilitare la funzione. Fai clic su &amp;quot;Enable&amp;quot; (Abilita) e sarai pronto a partire!&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;usare-la-cronologia-degli-appunti&quot; tabindex=&quot;-1&quot;&gt;Usare la cronologia degli appunti &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-use-multiple-clipboard-feature-on-macOS-26-tahoe/#usare-la-cronologia-degli-appunti&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Una volta abilitata, usare la cronologia degli appunti è semplicissimo. Ogni volta che desideri accedere a un elemento copiato in precedenza:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Premi &lt;code&gt;Command (⌘)&lt;/code&gt; + &lt;code&gt;Spazio&lt;/code&gt; per aprire &lt;strong&gt;Spotlight&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Premi &lt;code&gt;Command (⌘)&lt;/code&gt; + &lt;code&gt;4&lt;/code&gt; per visualizzare la scheda Clipboard in Spotlight.&lt;/li&gt;
&lt;li&gt;Vedrai un elenco dei testi, link e immagini che hai copiato.&lt;/li&gt;
&lt;li&gt;Usa i tasti freccia o il mouse per selezionare l&#39;elemento desiderato.&lt;/li&gt;
&lt;li&gt;Premi &lt;code&gt;Invio&lt;/code&gt; o fai clic sull&#39;elemento per ricopiarlo negli appunti.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Da lì, puoi incollarlo ovunque usando la scorciatoia standard &lt;code&gt;Command (⌘)&lt;/code&gt; + &lt;code&gt;V&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;alcune-cose-da-notare&quot; tabindex=&quot;-1&quot;&gt;Alcune cose da notare &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-use-multiple-clipboard-feature-on-macOS-26-tahoe/#alcune-cose-da-notare&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Anche se questo è un enorme passo avanti per macOS, vale la pena notare alcune delle sue attuali limitazioni. Ad esempio, salva gli elementi copiati solo per circa otto ore e non c&#39;è modo di fissare (pin) o salvare gli elementi in modo permanente. Se hai bisogno di una soluzione più avanzata con funzioni come scorciatoie personalizzate, cronologia illimitata o filtri intelligenti, un&#39;app di terze parti potrebbe essere ancora la scelta migliore.&lt;/p&gt;
&lt;p&gt;Ma per l&#39;utente medio, questa nuova funzione integrata rappresenta un notevole incremento di produttività e un&#39;aggiunta davvero gradita a macOS. Niente più corse a ricopiare!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Video del talk: &quot;Debugging and Optimizing Interaction to Next Paint (INP) for a Smoother Web&quot;, Meetup Performance Observer</title>
		<link href="https://andreaverlicchi.eu/it/blog/performance-observer-meetup-talk/"/>
		<updated>2025-04-16T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/performance-observer-meetup-talk/</id>
		<content type="html">&lt;p&gt;Il &lt;time datetime=&quot;2025-04-16&quot;&gt;16 aprile 2025&lt;/time&gt;, ho avuto il piacere di parlare a uno degli eccellenti meetup di Performance Observer. La community di Performance Observer si concentra sulla condivisione di conoscenze e spunti pratici sul monitoraggio e sull&#39;ottimizzazione delle prestazioni web. Potete consultare i loro eventi passati e futuri &lt;a href=&quot;https://performanceobserver.dev/events/&quot;&gt;qui&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Il mio talk era intitolato &amp;quot;Debugging and Optimizing Interaction to Next Paint (INP) for a Smoother Web&amp;quot;. Ecco la registrazione video della sessione:&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/pCNvVC5aTqk?si=or7DgTYR2KUYQAZ0&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; referrerpolicy=&quot;strict-origin-when-cross-origin&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;In questo intervento ho approfondito gli aspetti pratici dell&#39;identificazione e della risoluzione dei problemi relativi all&#39;Interaction to Next Paint (INP). Ho illustrato le cause più comuni di scarsa reattività che ho riscontrato e mostrato le tecniche da utilizzare con i developer tools dei browser e i dati di monitoraggio delle prestazioni per individuare i colli di bottiglia. L&#39;obiettivo era fornire strategie attuabili per migliorare la velocità di interazione dell&#39;utente e ottenere migliori punteggi INP, mantenendo l&#39;esperienza d&#39;uso scattante.&lt;/p&gt;
&lt;p&gt;I meetup di Performance Observer sono una fantastica serie di eventi dedicati a tutto ciò che riguarda le prestazioni web, e ospitano regolarmente talk di esperti del settore su monitoraggio, ottimizzazione e sulle ultime metriche prestazionali. È stato fantastico dare il mio contributo a questa community così competente.&lt;/p&gt;
&lt;figure&gt;
  &lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/PUBDOGIwN3-800.webp 800w&quot; sizes=&quot;800px&quot;&gt;&lt;img alt=&quot;Relatore che parla durante il meetup online di Performance Observer. È visibile una slide con dati sulle prestazioni.&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/PUBDOGIwN3-800.png&quot; width=&quot;800&quot; height=&quot;448&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Presentazione durante la sessione del meetup di Performance Observer.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://docs.google.com/presentation/d/1_okzKg2FagXQHG68f4yiwPwS5XGfK5aFY3CWi7QmOG8/edit&quot;&gt;📽️ Slide&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Presentazione di yieldy-for-loop: un pacchetto npm per mantenere i loop non bloccanti (e la UI fluida)</title>
		<link href="https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/"/>
		<updated>2025-01-14T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/</id>
		<content type="html">&lt;p&gt;Se avete mai dovuto elaborare migliaia (o milioni) di elementi in JavaScript, avrete probabilmente sperimentato quel fastidioso lag o blocco dell&#39;interfaccia utente. Può accadere quando si eseguono cicli intensivi sul thread principale, bloccando gli aggiornamenti dell&#39;interfaccia. Per affrontare questo problema, ho creato un pacchetto npm chiamato &lt;a href=&quot;https://www.npmjs.com/package/yieldy-for-loop&quot;&gt;yieldy-for-loop&lt;/a&gt;. Questa piccola utility vi aiuta a suddividere cicli di grandi dimensioni in blocchi, cedendo periodicamente il controllo al browser per far sì che la vostra applicazione rimanga reattiva.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/OdlkifvJiX-648.webp 648w, https://andreaverlicchi.eu/img/OdlkifvJiX-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/OdlkifvJiX-648.png 648w, https://andreaverlicchi.eu/img/OdlkifvJiX-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;yieldy-for-loop su npm&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/OdlkifvJiX-648.png&quot; width=&quot;1296&quot; height=&quot;693&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;yieldy-for-loop sul sito web di npm&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;contesto&quot; tabindex=&quot;-1&quot;&gt;Contesto &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/#contesto&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;I &lt;strong&gt;long task&lt;/strong&gt; sono un comune collo di bottiglia per le prestazioni nelle applicazioni front-end. Quando il thread principale è occupato a eseguire cicli di grandi dimensioni, i browser non possono aggiornare l&#39;interfaccia utente e gli utenti potrebbero notare una mancanza di reattività o uno scrolling a scatti. Ispirato dall&#39;articolo &lt;a href=&quot;https://calendar.perfplanet.com/2024/breaking-up-with-long-tasks-or-how-i-learned-to-group-loops-and-wield-the-yield/&quot;&gt;“Breaking up with long tasks, or how I learned to group loops and wield the yield” (PerfPlanet 2024)&lt;/a&gt;, volevo una funzione semplice e riutilizzabile che potesse:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Suddividere cicli di grandi dimensioni&lt;/strong&gt; in lotti (batch) più piccoli.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cedere il controllo al browser (yield)&lt;/strong&gt; dopo ogni lotto, dando al motore di rendering la possibilità di aggiornare la pagina e all&#39;utente quella di interagire.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adattarsi&lt;/strong&gt; a seconda che il documento sia visibile o nascosto, dato che il lavoro svolto in una scheda in background (nascosta) può essere deprioritarizzato o addirittura sospeso in molti browser.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Così è nato yieldy-for-loop.&lt;/p&gt;
&lt;h2 id=&quot;cosa-fa&quot; tabindex=&quot;-1&quot;&gt;Cosa fa &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/#cosa-fa&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Iterazione non bloccante&lt;/strong&gt;: elabora i vostri elementi in lotti, con l&#39;obiettivo di rimanere entro una determinata frazione di tempo (ad es. 33ms per puntare a circa 30 FPS).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Logica di auto-yield&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;Se la pagina è &lt;strong&gt;nascosta&lt;/strong&gt;, cede il controllo meno frequentemente (ad es. ogni 500ms) per risparmiare risorse.&lt;/li&gt;
&lt;li&gt;Se la pagina è &lt;strong&gt;visibile&lt;/strong&gt;, cede il controllo più di frequente per mantenere fluide le animazioni e le interazioni dell&#39;utente.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compatibilità del browser&lt;/strong&gt;: utilizza una competizione (race) tra un breve &lt;code&gt;setTimeout&lt;/code&gt; e &lt;code&gt;requestAnimationFrame&lt;/code&gt;, ed eventualmente chiama la &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Scheduler&quot;&gt;Scheduler API&lt;/a&gt; se disponibile.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;installazione&quot; tabindex=&quot;-1&quot;&gt;Installazione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/#installazione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-bash&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; yieldy-for-loop&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;esempio-di-utilizzo&quot; tabindex=&quot;-1&quot;&gt;Esempio di utilizzo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/#esempio-di-utilizzo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; yieldyForLoop &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;yieldy-for-loop&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; items &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Array&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100000&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;_&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; i&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;processItem&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// La vostra logica di elaborazione pesante&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Processing item:&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; item&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Starting yieldy loop...&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  
  &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;yieldyForLoop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;items&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; processItem&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;fps&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;              &lt;span class=&quot;token comment&quot;&gt;// Punta a circa 30 fotogrammi al secondo&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;hiddenThreshold&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Soglia di yield (in ms) quando la scheda è nascosta&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;All items processed without blocking the UI!&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;come-funziona&quot; tabindex=&quot;-1&quot;&gt;Come funziona &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/#come-funziona&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Calcolo della frazione di tempo (Time Slice)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;I fotogrammi al secondo (FPS) predefiniti sono impostati a &lt;strong&gt;30&lt;/strong&gt;, quindi viene calcolata una durata del lotto di circa 33ms.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Controllo &lt;code&gt;shouldYield()&lt;/code&gt;&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;Prima di elaborare ciascun elemento, la funzione controlla quanto tempo è trascorso dall&#39;ultimo yield.&lt;/li&gt;
&lt;li&gt;Se supera la soglia (ad es. circa 33ms, o 500ms se il documento è nascosto), cede nuovamente il controllo al browser.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Meccanismi di Yielding&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Pagina nascosta&lt;/strong&gt;: utilizza &lt;code&gt;setTimeout(resolve, 1)&lt;/code&gt; — il tempo minimo per consentire ad altri task di inserirsi.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pagina visibile&lt;/strong&gt;: utilizza una combinazione di &lt;code&gt;requestAnimationFrame&lt;/code&gt; e un breve timeout. Se il metodo sperimentale &lt;code&gt;scheduler.yield()&lt;/code&gt; è disponibile, chiama anche quello.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Dividendo il ciclo in lotti, il browser ha lo spazio di manovra necessario per renderizzare la pagina, rispondere agli input dell&#39;utente ed eseguire altri script, evitando così il temuto problema della &amp;quot;pagina che non risponde&amp;quot;.&lt;/p&gt;
&lt;h2 id=&quot;perche-ne-avete-bisogno&quot; tabindex=&quot;-1&quot;&gt;Perché ne avete bisogno &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/#perche-ne-avete-bisogno&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Migliore esperienza utente&lt;/strong&gt;: scrolling fluido, pulsanti reattivi e nessun blocco improvviso.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Facile da usare&lt;/strong&gt;: basta racchiudere la normale logica del ciclo all&#39;interno di &lt;code&gt;yieldyForLoop&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Micro-ottimizzato&lt;/strong&gt;: il codice è ridotto all&#39;essenziale e lineare, quindi facile da mantenere o personalizzare.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;prossimi-passi&quot; tabindex=&quot;-1&quot;&gt;Prossimi passi &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/#prossimi-passi&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Provatelo&lt;/strong&gt;: installate il pacchetto, importatelo e integratelo in qualsiasi ciclo pesante abbiate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contributi&lt;/strong&gt;: segnalazioni di bug e pull request sono i benvenuti! Date un&#39;occhiata alla &lt;a href=&quot;https://github.com/YourUsername/yieldy-for-loop&quot;&gt;repo GitHub&lt;/a&gt; per segnalare problemi, richiedere funzionalità o aprire PR.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Passate parola&lt;/strong&gt;: se lo trovate utile, fatelo sapere agli altri.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ringraziamenti&quot; tabindex=&quot;-1&quot;&gt;Ringraziamenti &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/#ringraziamenti&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Un ringraziamento speciale a &lt;a href=&quot;https://rviscomi.dev/&quot;&gt;Rick Viscomi&lt;/a&gt; per aver scritto l&#39;articolo su PerfPlanet che mi ha spinto a realizzare questo strumento.
Suddividere i task di grandi dimensioni in blocchi più piccoli è diventata una strategia prestazionale chiave, e &lt;code&gt;yieldy-for-loop&lt;/code&gt; mira a renderne ancora più semplice l&#39;adozione.&lt;/p&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/introducing-yieldy-for-loop/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;I cicli lunghi non devono per forza tradursi in interfacce utente bloccate. Cedendo periodicamente il controllo al browser, potete mantenere un&#39;esperienza fluida per i vostri utenti. &lt;code&gt;yieldy-for-loop&lt;/code&gt; si occupa della parte difficile con pochissimo codice, lasciandovi liberi di concentrarvi su ciò che sapete fare meglio: creare fantastiche applicazioni web.&lt;/p&gt;
&lt;p&gt;Se avete domande, contattatemi o aprite una segnalazione su GitHub.
Ora non vi resta che provarlo e mantenere i vostri cicli fluidi.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Ottimizzare l&#39;uso degli SVG per le prestazioni web: una guida completa</title>
		<link href="https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/"/>
		<updated>2024-12-05T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/</id>
		<content type="html">&lt;p&gt;In una recente conversazione tra appassionati di web performance, è stato approfondito il tema del caricamento efficiente degli SVG (Scalable Vector Graphics) sui siti web. La discussione si è concentrata sui metodi migliori per integrare gli SVG, in particolare le icone, con un occhio di riguardo alle prestazioni. Sono state confrontate diverse tecniche: SVG inline, il tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;, gli sfondi CSS e gli sprite SVG. Ecco un riassunto dei punti chiave e dei consigli emersi da quel confronto.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/7JYSvCHYQ1-648.webp 648w, https://andreaverlicchi.eu/img/7JYSvCHYQ1-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/7JYSvCHYQ1-648.jpeg 648w, https://andreaverlicchi.eu/img/7JYSvCHYQ1-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Un set di icone SVG&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/7JYSvCHYQ1-648.jpeg&quot; width=&quot;1296&quot; height=&quot;863&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Le immagini SVG sono ampiamente utilizzate per creare icone sul web&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Vediamo nel dettaglio i metodi per caricare gli SVG.&lt;/p&gt;
&lt;h2 id=&quot;1-svg-inline&quot; tabindex=&quot;-1&quot;&gt;1. SVG inline &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#1-svg-inline&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Utilizzo:&lt;/strong&gt; Ideale per icone above-the-fold come loghi o pulsanti di menu, specialmente quando è necessario stilizzare o animare singoli elementi all&#39;interno dell&#39;SVG usando CSS o JavaScript.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Vantaggi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Flessibilità di stile:&lt;/strong&gt; consente la manipolazione diretta degli elementi SVG.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rendering immediato:&lt;/strong&gt; nessuna richiesta HTTP aggiuntiva poiché l&#39;SVG è parte integrante dell&#39;HTML.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Svantaggi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Aumento delle dimensioni del DOM:&lt;/strong&gt; ogni SVG inline si aggiunge al DOM, il che può influire sulle prestazioni.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Impatto prestazionale:&lt;/strong&gt; elementi selezionabili e stilizzabili possono influire sulle prestazioni di rendering.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Best practice:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;URL-Encoding invece di Base64:&lt;/strong&gt; quando si incorporano SVG inline tramite data URL, è preferibile utilizzare l&#39;URL-encoding rispetto a base64 per ottenere una compressione migliore.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limitarne l&#39;uso:&lt;/strong&gt; riservare gli SVG inline per elementi grafici essenziali above-the-fold che richiedono interattività.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;2-il-tag-img&quot; tabindex=&quot;-1&quot;&gt;2. Il tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#2-il-tag-img&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Utilizzo:&lt;/strong&gt; Adatto per icone e immagini generiche dove non sono richiesti stili particolari o interazioni.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Vantaggi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Lazy Loading:&lt;/strong&gt; supporta l&#39;attributo &lt;code&gt;loading=&amp;quot;lazy&amp;quot;&lt;/code&gt; per posticipare il caricamento delle immagini finché non sono necessarie.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DOM più snello:&lt;/strong&gt; mantiene il DOM più pulito rispetto agli SVG inline.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Svantaggi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Stile limitato:&lt;/strong&gt; non è possibile manipolare direttamente gli elementi interni dell&#39;SVG tramite CSS o JavaScript.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contenuto statico:&lt;/strong&gt; non è l&#39;ideale per icone che devono cambiare colore o forma al passaggio del mouse.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Best practice:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Attributi delle dimensioni:&lt;/strong&gt; includere sempre &lt;code&gt;width&lt;/code&gt; e &lt;code&gt;height&lt;/code&gt; per evitare spostamenti di layout (layout shift).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Evitare il lazy loading per gli asset immediati:&lt;/strong&gt; non applicare il lazy-loading a immagini cruciali per il rendering iniziale o per interazioni immediate come gli stati di hover.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;3-immagini-di-sfondo-css&quot; tabindex=&quot;-1&quot;&gt;3. Immagini di sfondo CSS &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#3-immagini-di-sfondo-css&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Utilizzo:&lt;/strong&gt; Ideale per elementi grafici decorativi o pattern di sfondo che non richiedono interattività.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Vantaggi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Separazione dei ruoli (Separation of Concerns):&lt;/strong&gt; mantiene le immagini di sfondo nel CSS, lasciando la struttura HTML pulita.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Caricamento condizionale:&lt;/strong&gt; può essere combinato con media query o JavaScript per design reattivi.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Svantaggi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Controllo limitato:&lt;/strong&gt; più difficile da manipolare o animare rispetto agli SVG inline.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Problemi di accessibilità:&lt;/strong&gt; le immagini di sfondo non vengono lette dagli screen reader.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Best practice:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Lazy Loading:&lt;/strong&gt; utilizzare librerie JavaScript come &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt; per posticipare il caricamento delle immagini di sfondo non immediatamente visibili.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Utilizzo appropriato:&lt;/strong&gt; riservare solo a elementi decorativi non critici.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;4-sprite-svg-e-tag-use&quot; tabindex=&quot;-1&quot;&gt;4. Sprite SVG e tag &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#4-sprite-svg-e-tag-use&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Utilizzo:&lt;/strong&gt; Efficace quando si hanno più istanze di icone che devono essere stilizzate o animate, e quando gli SVG vengono serviti dallo stesso dominio.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Vantaggi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Simboli riutilizzabili:&lt;/strong&gt; consente di definire i simboli SVG una sola volta e richiamarli più volte.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Capacità di stile:&lt;/strong&gt; consente la stilizzazione CSS degli elementi SVG come se fossero inline.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Meno richieste HTTP:&lt;/strong&gt; raggruppa le icone in un unico file.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Svantaggi:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Complessità di configurazione iniziale:&lt;/strong&gt; richiede la creazione e la gestione di un file di sprite esterno.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Same-Origin Policy:&lt;/strong&gt; lo sprite SVG esterno deve trovarsi sullo stesso dominio a causa delle restrizioni di sicurezza del browser.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Best practice:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Organizzazione efficiente:&lt;/strong&gt; raggruppare le icone usate più di frequente in un unico file di sprite.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Soluzioni di fallback:&lt;/strong&gt; implementare alternative per i browser che potrebbero non supportare gli sprite SVG esterni.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;scegliere-il-metodo-in-base-al-caso-d-uso&quot; tabindex=&quot;-1&quot;&gt;Scegliere il metodo in base al caso d&#39;uso &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#scegliere-il-metodo-in-base-al-caso-d-uso&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Scegliete il metodo di caricamento degli SVG in base alle esigenze specifiche del progetto. SVG inline per elementi interattivi, tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; per icone statiche, sfondi CSS per immagini decorative e sprite SVG per icone riutilizzabili e stilizzabili.&lt;/p&gt;
&lt;h2 id=&quot;considerazioni-sulle-prestazioni&quot; tabindex=&quot;-1&quot;&gt;Considerazioni sulle prestazioni &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#considerazioni-sulle-prestazioni&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;La dimensione del DOM conta:&lt;/strong&gt; un numero eccessivo di SVG inline può appesantire il DOM e peggiorare le prestazioni.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lazy loading intelligente:&lt;/strong&gt; usate il lazy loading per le immagini non immediatamente necessarie, ma evitatelo per le risorse necessarie per le interazioni iniziali o per gli effetti di hover.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tecniche di compressione:&lt;/strong&gt; preferite l&#39;URL-encoding rispetto a base64 quando incorporate gli SVG nei data URL per mantenere rapporti di compressione migliori.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;stile-e-interattivita&quot; tabindex=&quot;-1&quot;&gt;Stile e interattività &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#stile-e-interattivita&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Icone interattive:&lt;/strong&gt; usate gli SVG inline o gli sprite SVG con il tag &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; quando le icone devono rispondere alle interazioni dell&#39;utente.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Icone statiche:&lt;/strong&gt; usate il tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; per le icone che non richiedono interattività per mantenere il DOM leggero.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;accessibilita-e-semantica&quot; tabindex=&quot;-1&quot;&gt;Accessibilità e semantica &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#accessibilita-e-semantica&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Attributi corretti:&lt;/strong&gt; includete l&#39;attributo &lt;code&gt;alt&lt;/code&gt; per i tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; e &lt;code&gt;aria-label&lt;/code&gt; o &lt;code&gt;role=&amp;quot;img&amp;quot;&lt;/code&gt; per gli SVG inline per migliorare l&#39;accessibilità.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Evitare immagini di sfondo per contenuti essenziali:&lt;/strong&gt; poiché le immagini di sfondo CSS vengono ignorate dalle tecnologie assistive, non utilizzatele per contenuti importanti.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;evitare-tecniche-superate&quot; tabindex=&quot;-1&quot;&gt;Evitare tecniche superate: &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#evitare-tecniche-superate&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sprite di immagini:&lt;/strong&gt; i tradizionali sprite di immagini (CSS sprites) sono ampiamente considerati obsoleti a causa della complessità e dei rendimenti decrescenti nell&#39;era di HTTP/2 e HTTP/3.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Font di icone (Icon Fonts):&lt;/strong&gt; valutate la migrazione dai font di icone agli SVG per una migliore scalabilità e flessibilità di stile, come descritto nell&#39;&lt;a href=&quot;https://calendar.perfplanet.com/2021/from-fonts-to-svg-an-icon-migration-strategy/&quot;&gt;articolo di Erwin Hofman&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ottimizzare l&#39;uso degli SVG sui siti web richiede un equilibrio tra prestazioni, manutenibilità e funzionalità. Scegliendo il metodo appropriato per caricare gli SVG in base al loro scopo — che si tratti di visualizzazione statica, personalizzazione dello stile o interattività — è possibile migliorare sia l&#39;esperienza utente sia le prestazioni del sito. Ricordate di considerare fattori come la dimensione del DOM, il lazy loading e l&#39;accessibilità quando implementate gli SVG nei vostri progetti.&lt;/p&gt;
&lt;h2 id=&quot;approfondimenti&quot; tabindex=&quot;-1&quot;&gt;Approfondimenti &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/loading_svg_images_icons_performance_considerations/#approfondimenti&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://svgsprit.es/&quot;&gt;SVG sprites generator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://tympanus.net/codrops/2015/07/16/styling-svg-use-content-css/&quot;&gt;Styling SVG &lt;use&gt; Content with CSS&lt;/use&gt;&lt;/a&gt; di Sara Soueidan&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://calendar.perfplanet.com/2021/from-fonts-to-svg-an-icon-migration-strategy/&quot;&gt;From Fonts to SVG: An Icon Migration Strategy&lt;/a&gt; di Erwin Hofman&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;Repository GitHub di vanilla-lazyload&lt;/a&gt; di Andrea Verlicchi (il sottoscritto)&lt;/li&gt;
&lt;/ul&gt;
</content>
	</entry>
	
	<entry>
		<title>Video del talk: &quot;How I made the web more responsive — real-world case studies of INP optimizations&quot;, conferenza We Love Speed 2024</title>
		<link href="https://andreaverlicchi.eu/it/blog/how-i-made-web-more-responsive-inp-video-we-love-speed-2024-nantes/"/>
		<updated>2024-11-26T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/how-i-made-web-more-responsive-inp-video-we-love-speed-2024-nantes/</id>
		<content type="html">&lt;p&gt;Il &lt;time datetime=&quot;2024-07-17&quot;&gt;17 settembre 2024&lt;/time&gt;, ho parlato alla conferenza We Love Speed 2024 su come migliorare la reattività del web. In particolare, ho spiegato come fare il debug ed evitare le interazioni lente sulla base della mia esperienza nell&#39;audit dell&#39;Interaction to Next Paint (INP) sui siti web dei clienti.&lt;/p&gt;
&lt;p&gt;Il titolo del talk era &amp;quot;How I made the web more responsive - real-world case studies of INP optimizations&amp;quot;, in francese &amp;quot;Comment j’ai rendu le web plus réactif — études de cas concrets d’optimisations d’INP&amp;quot;, e questo è il video del mio intervento.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/FDb4aKLIVsI?si=WNNwr8DcyRAplbKB&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; referrerpolicy=&quot;strict-origin-when-cross-origin&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Dopo una spiegazione iniziale dell&#39;INP, mostro come fare il debug delle interazioni lente utilizzando sia Chrome DevTools sia i dati RUM (Real User Monitoring). Illustro poi tre errori comuni che ho riscontrato durante l&#39;audit dell&#39;INP su decine di siti web e spiego come evitarli per garantire interazioni scattanti per l&#39;utente e mantenere l&#39;INP sotto i 200 millisecondi.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/qB1-i3O1fD-648.webp 648w, https://andreaverlicchi.eu/img/qB1-i3O1fD-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/qB1-i3O1fD-648.jpeg 648w, https://andreaverlicchi.eu/img/qB1-i3O1fD-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi parla sul palco di We Love Speed, Nantes. La slide mostra il flame chart della traccia di performance eseguita dopo un&#39;ottimizzazione dell&#39;INP&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/qB1-i3O1fD-648.jpeg&quot; width=&quot;1296&quot; height=&quot;863&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Sul palco di We Love Speed 2024.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://docs.google.com/presentation/d/1kSHr9mEN2Q4Nyis8uWvxoA3_pqOIywr3TXCLeO_-4qA/edit&quot;&gt;📽️ Slide&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Il web è morto, lunga vita al web (repost)</title>
		<link href="https://andreaverlicchi.eu/it/blog/the-web-is-dead-long-live-the-web-antonio-moro-itomi/"/>
		<updated>2024-11-22T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/the-web-is-dead-long-live-the-web-antonio-moro-itomi/</id>
		<content type="html">&lt;p&gt;👀 L&#39;autore di questo articolo è Antonio Moro, in arte Itomi.
&lt;br&gt;&lt;a href=&quot;https://www.clickbaiting.it/p/il-web-e-morto-lunga-vita-al-web&quot;&gt;🇮🇹 Articolo originale&lt;/a&gt; | &lt;a href=&quot;https://itomi.studio/&quot;&gt;Itomi Studio&lt;/a&gt; | &lt;a href=&quot;https://itomi.studio/about/&quot;&gt;About&lt;/a&gt; | &lt;a href=&quot;https://itomi.shop/&quot;&gt;Shop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;La chiusura di Badtaste.it è solo l&#39;ultimo chiodo su una bara che in realtà è chiusa da anni: l&#39;editoria online come l&#39;abbiamo conosciuta negli ultimi vent&#39;anni è ormai morta e sepolta.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/WmlI0fe2k1-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Meme del ragazzino che fa il pollice in su davanti alla telecamera mentre usa un computer&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/WmlI0fe2k1-648.jpeg&quot; width=&quot;648&quot; height=&quot;364&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;p&gt;Ieri si è diffusa la notizia che Badtaste.it chiuderà dopo 20 anni di attività. Non è una sorpresa, almeno non per me. È solo l&#39;ultimo di molti segnali degli ultimi cinque anni. E chi dà la colpa alla pandemia ha capito ben poco di quello che è successo realmente.&lt;/p&gt;
&lt;p&gt;Sono uno di quelli che ha fatto parte dell&#39;&amp;quot;editoria online&amp;quot;, come è stato di moda chiamarla per anni, in Italia fin dai suoi albori — quando si chiamava semplicemente &amp;quot;scrivere su un blog&amp;quot;. La festa è durata 20 anni, poi è finita. E anche se qualcuno si attarda ancora all&#39;uscita, non c&#39;è molto da fare. La musica è finita.&lt;/p&gt;
&lt;p&gt;Per fortuna ho avuto la lucidità di andarmene prima che implodesse completamente. Tre anni fa ho lasciato la direzione del sito che ho fondato e diretto per 12 anni e ho avviato una casa editrice basata su un progetto completamente diverso — che ritorna all&#39;oggetto fisico e abbandona il concetto di &amp;quot;tutto digitale&amp;quot; tanto caro a questo settore negli ultimi due decenni.&lt;/p&gt;
&lt;p&gt;Il web è morto, e in gran parte si è ucciso da solo. Si è ucciso quando ha permesso a una singola azienda e a un singolo motore di ricerca di dettare le regole su cui si basava.&lt;/p&gt;
&lt;p&gt;Si è ucciso quando ha consegnato a pochi social network le community che aveva faticosamente costruito nel corso degli anni.&lt;/p&gt;
&lt;p&gt;Per anni Google ha dettato come gli articoli online dovessero essere scritti, pubblicati e formattati. Quali parole chiave e quante dovessero essere incluse in ogni pezzo affinché avesse senso pubblicarlo. Abbiamo smesso di scrivere per il nostro pubblico e, senza nemmeno rendercene conto, abbiamo iniziato a scrivere per l&#39;algoritmo di Google — per ottenere più traffico, per portare più persone sui nostri contenuti. Siamo diventati dipendenti da una sostanza che non ci ha mai nutrito: un traffico cieco e inutile fatto di persone che non sapevano nemmeno cosa stessero leggendo o dove lo stessero leggendo. Abbiamo cancellato l&#39;identità dei nostri siti e blog, trasformandoli in sterili contenitori di contenuti privi di personalità.&lt;/p&gt;
&lt;p&gt;Facebook, l&#39;unica altra forte fonte di traffico, ha completato l&#39;opera. Ci ha portato via le nostre community, i nostri lettori fedeli. Ha tolto le interazioni, divorando ciò che avevamo costruito. Nel momento in cui abbiamo iniziato a considerare normale la scritta &amp;quot;Commenti: Zero&amp;quot; sotto i nostri articoli, i nostri siti hanno iniziato a morire in modo irreversibile.&lt;/p&gt;
&lt;p&gt;Abbiamo abbandonato un pubblico piccolo, fedele e attivo per uno vasto, disinteressato e inconsapevole.&lt;/p&gt;
&lt;p&gt;I blog e i siti editoriali sono nati perché pochi appassionati volevano condividere le proprie idee, opinioni e contenuti. Lo facevamo gratis, nel nostro tempo libero. E chi ci leggeva lo faceva gratis. E ne eravamo felici.&lt;/p&gt;
&lt;p&gt;Poi è diventato un lavoro, e capire come guadagnarci è diventato fondamentale. Una volta regalati i frutti del nostro lavoro — i nostri contenuti — l&#39;unica opzione rimasta era monetizzare attraverso banner e campagne pubblicitarie.&lt;/p&gt;
&lt;p&gt;Su Lega Nerd ho resistito per anni, facendo solo campagne &amp;quot;native&amp;quot; con inserzionisti in linea con la mia nicchia, riducendo al minimo i banner pubblicitari perché rovinavano la leggibilità e l&#39;esperienza complessiva dell&#39;utente. Nel corso del tempo, l&#39;economia di Internet e la pubblicità online si sono spostate sempre più verso nuovi attori — oggi li chiamiamo &amp;quot;influencer&amp;quot;, ma sono solo creatori di contenuti come lo eravamo noi, solo che lo fanno in modo diverso e su altre piattaforme, raggiungendo un pubblico enorme.&lt;/p&gt;
&lt;p&gt;Gli inserzionisti hanno impiegato qualche anno a capire il potere degli influencer, ma alla fine il budget si è spostato sui creator. Gestire una campagna per il proprio sito era già difficile cinque anni fa, figuriamoci oggi.&lt;/p&gt;
&lt;p&gt;Ora, i padroni assoluti dei siti web sono i banner. Sono esplosi alla fine degli anni 2010, grazie all&#39;ascesa delle piattaforme di &amp;quot;Real-Time Bidding&amp;quot; che ne hanno aumentato la redditività, e noi ci siamo buttati a capofitto in questa nuova opportunità, riempiendo i nostri siti di spazzatura. Spazzatura in ogni paragrafo. Spazzatura che compare sopra i contenuti. Spazzatura che si avvia da sola in autoplay e rimane fissa mentre scorri per leggere. Spazzatura ovunque.&lt;/p&gt;
&lt;p&gt;Avevamo bisogno di più traffico, e lo abbiamo rincorso con ogni mezzo. Più traffico significava più visualizzazioni di pagina, più visualizzazioni significavano più banner mostrati, e più banner significavano più soldi per tenere a galla la baracca.&lt;/p&gt;
&lt;p&gt;Avevamo bisogno di più traffico da Google, quindi abbiamo scritto quello che voleva, ricostruito i nostri siti da zero secondo le sue specifiche, ottimizzato tutto come ci veniva dettato.&lt;/p&gt;
&lt;p&gt;Avevamo bisogno di più traffico dai social media, quindi abbiamo iniziato a pubblicare centinaia, migliaia di notizie. Attualità. Giusto poche righe, poca sostanza, ma sufficienti per le persone che scorrono Facebook senza pensare. Migliaia di notizie al giorno. Poi siamo passati al clickbait — per far cliccare le persone e farle atterrare sui nostri siti. E le fake news — centinaia, migliaia di siti creati esclusivamente per generare traffico e monetizzare i banner.&lt;/p&gt;
&lt;p&gt;Spazzatura, ricoperta da altra spazzatura.&lt;/p&gt;
&lt;p&gt;E chi ci credeva davvero, chi voleva pubblicare contenuti interessanti, indipendenti, educativi, informativi? Fregato.&lt;/p&gt;
&lt;p&gt;Fregato perché non può competere con chi gioca con quelle regole senza trasformare a sua volta il proprio sito in spazzatura. Vuoi viverci o vuoi scrivere per quattro gatti senza guadagnare nulla?&lt;/p&gt;
&lt;p&gt;Gli anni della pandemia hanno ulteriormente gonfiato il web in modo artificiale. Il traffico è cresciuto, i banner si sono moltiplicati ancora di più e la pazienza degli utenti si è esaurita. Sono stati solo un paio d&#39;anni di buone notizie per gli editori prima di piombare nuovamente nella realtà.&lt;/p&gt;
&lt;p&gt;Ora i banner non pagano quasi nulla. Le campagne sono sparite. Monetizzare un sito editoriale è più difficile che mai. Abbiamo reso il web brutto e ora nessuno vuole più guardarlo. Le persone si informano altrove, senza dover subire la spazzatura che ricopre i siti internet.&lt;/p&gt;
&lt;p&gt;Abbiamo regalato i nostri contenuti per 20 anni e ora nessuno vuole pagarli — specialmente dopo che abbiamo pubblicato spazzatura per anni. Niente abbonamenti. Niente aree &amp;quot;premium&amp;quot;. Non funziona più nulla e non sappiamo dove sbattere la testa.&lt;/p&gt;
&lt;p&gt;È ora di chiudere. Di fare altro.&lt;/p&gt;
&lt;p&gt;I giovani si inventeranno qualcosa di nuovo, qualcosa di innovativo e adatto ai tempi. Tempi veloci. Tempi brutali.&lt;/p&gt;
&lt;p&gt;Vedo un timido ritorno al passato. Stanno nascendo piccole community di persone stanche della bulimia dei social media. Nascono piccoli progetti editoriali che usano il web ma non si affidano esclusivamente ad esso. Il web non morirà mai del tutto.&lt;/p&gt;
&lt;p&gt;Il web è morto. Lunga vita al web.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>La mia esperienza a performance.now() 2024: la principale conferenza sulla web performance in Europa</title>
		<link href="https://andreaverlicchi.eu/it/blog/performance-now-2024-experience-europe-web-performance-conference/"/>
		<updated>2024-11-16T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/performance-now-2024-experience-europe-web-performance-conference/</id>
		<content type="html">&lt;p&gt;Dal &lt;strong&gt;14 al 15 novembre&lt;/strong&gt;, ho partecipato a &lt;a href=&quot;https://www.perfnow.nl/&quot;&gt;&lt;strong&gt;performance.now&lt;/strong&gt;&lt;/a&gt; ad &lt;strong&gt;Amsterdam&lt;/strong&gt;, la conferenza più stimata nel campo delle performance web in Europa. Per chi, come me, è profondamente immerso in questa nicchia dello sviluppo web, incontrare altre persone con le stesse passioni all&#39;evento è stato sia stimolante sia prezioso.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/VIH8mSoDfg-648.webp 648w, https://andreaverlicchi.eu/img/VIH8mSoDfg-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/VIH8mSoDfg-648.png 648w, https://andreaverlicchi.eu/img/VIH8mSoDfg-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;performance.now() – Andrea Verlicchi – @verlok (he/him) – Speed Kit, IT, – Sponsor: Google, SpeedCurve, Mozilla, Akamai, Sentry. L&#39;immagine contiene anche adesivi di Firefox, SpeedCurve #perfhero, No vanity metrics P50, Anti Javascript Javascript Club&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/VIH8mSoDfg-648.png&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Il mio badge di performance.now 2024, oltre a gadget e adesivi&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;contenuti-e-speaker-eccezionali&quot; tabindex=&quot;-1&quot;&gt;Contenuti e speaker eccezionali &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/performance-now-2024-experience-europe-web-performance-conference/#contenuti-e-speaker-eccezionali&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/yvWX-HFVbQ-648.webp 648w, https://andreaverlicchi.eu/img/yvWX-HFVbQ-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/yvWX-HFVbQ-648.png 648w, https://andreaverlicchi.eu/img/yvWX-HFVbQ-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Programma del primo e del secondo giorno, disponibile anche seguendo il link nella didascalia della figura&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/yvWX-HFVbQ-648.png&quot; width=&quot;1296&quot; height=&quot;1250&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Il &lt;a href=&quot;https://perfnow.nl/schedule&quot;&gt;programma&lt;/a&gt; delle due giornate di conferenza.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Fin dal primo momento è stato evidente che performance.now() si distingue per l&#39;&lt;strong&gt;alto livello dei contenuti e degli &lt;a href=&quot;https://perfnow.nl/speakers&quot;&gt;speaker&lt;/a&gt;&lt;/strong&gt;. Ogni sessione era curata nei minimi dettagli, con leader del settore che hanno affrontato una vasta gamma di sfide e soluzioni per le moderne performance web.&lt;/p&gt;
&lt;p&gt;I keynote hanno esplorato l&#39;evoluzione dello scenario della velocità del web, sottolineando la necessità critica di reattività e di metriche incentrate sull&#39;utente. I talk hanno affrontato svariati argomenti, dall&#39;impatto dell&#39;accessibilità sulle performance alle strategie pratiche per migliorare i Core Web Vitals, in particolare l&#39;INP (Interaction to Next Paint). Altre presentazioni si sono concentrate su strumenti avanzati, ottimizzazione dei font e riduzione dell&#39;impatto degli script di terze parti.&lt;/p&gt;
&lt;p&gt;Con studi di caso approfonditi e discussioni orientate al futuro, l&#39;evento ha mostrato tecniche all&#39;avanguardia e promosso una visione olistica delle web performance.&lt;/p&gt;
&lt;h2 id=&quot;connettersi-con-professionisti-affini&quot; tabindex=&quot;-1&quot;&gt;Connettersi con professionisti affini &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/performance-now-2024-experience-europe-web-performance-conference/#connettersi-con-professionisti-affini&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Uno dei momenti salienti della conferenza per me è stata l&#39;opportunità di &lt;strong&gt;connettermi con colleghi professionisti&lt;/strong&gt; che condividono la stessa passione per le performance web. Le numerose pause e la vivace festa serale hanno facilitato conversazioni significative e networking. È stato rigenerante scambiare idee, discutere di sfide ed esplorare potenziali collaborazioni con colleghi che comprendono davvero le complessità del nostro settore.&lt;/p&gt;
&lt;p&gt;Oltre a partecipare, ho avuto l&#39;onore di contribuire alla conferenza in due modi significativi.&lt;/p&gt;
&lt;h3 id=&quot;contribuire-all-help-desk-sponsorizzato-da-google&quot; tabindex=&quot;-1&quot;&gt;Contribuire all&#39;help desk sponsorizzato da Google &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/performance-now-2024-experience-europe-web-performance-conference/#contribuire-all-help-desk-sponsorizzato-da-google&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/vhmLxNlZ84-648.webp 648w, https://andreaverlicchi.eu/img/vhmLxNlZ84-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/vhmLxNlZ84-648.png 648w, https://andreaverlicchi.eu/img/vhmLxNlZ84-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Io all&#39;help desk con Morten Sorth e Ismail Gunsaya di Skyscanner&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/vhmLxNlZ84-648.png&quot; width=&quot;1296&quot; height=&quot;796&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Morten Sorth e Ismail Gunsaya di Skyscanner che mi chiedono consigli sull&#39;ottimizzazione dell&#39;INP&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Uno dei punti salienti per me è stata la partecipazione all&#39;&lt;strong&gt;Help Desk sponsorizzato da Google&lt;/strong&gt;, dove ho risposto per circa mezz&#39;ora alle domande dei partecipanti offrendo soluzioni alle loro sfide di web performance. Questa esperienza mi ha permesso non solo di restituire qualcosa alla community, ma anche di imparare dalla grande varietà di problemi e prospettive presentati da altri professionisti.&lt;/p&gt;
&lt;h3 id=&quot;partecipare-all-intervista-live-di-henri-helvetica-su-youtube&quot; tabindex=&quot;-1&quot;&gt;Partecipare all&#39;intervista live di &lt;strong&gt;Henri Helvetica su YouTube&lt;/strong&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/performance-now-2024-experience-europe-web-performance-conference/#partecipare-all-intervista-live-di-henri-helvetica-su-youtube&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;figure&gt;
	&lt;img alt=&quot;Henri Helvetica e io con un microfono verde e uno rosso durante lo streaming dal vivo&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/_gangJ34x9-648.webp&quot; width=&quot;1296&quot; height=&quot;863&quot; srcset=&quot;https://andreaverlicchi.eu/img/_gangJ34x9-648.webp 648w, https://andreaverlicchi.eu/img/_gangJ34x9-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;
	&lt;figcaption&gt;Henri Helvetica e io durante lo streaming dal vivo&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Un altro momento importante è stato partecipare all&#39;&lt;strong&gt;intervista dal vivo di Henri Helvetica su YouTube&lt;/strong&gt;. Essere intervistato da Henri mi ha dato l&#39;opportunità di condividere la mia esperienza e il mio background con un pubblico più vasto. L&#39;intervista ha approfondito il mio percorso e le mie sfide personali, ed è stato fantastico.&lt;/p&gt;
&lt;p&gt;Date un&#39;occhiata al &lt;a href=&quot;https://www.youtube.com/channel/UC927gvqy8i0vw0q5-6-WWBA&quot;&gt;canale YouTube di Henri Helvetica&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;pre-evento-performance-sync-di-mozilla&quot; tabindex=&quot;-1&quot;&gt;Pre-evento: Performance.Sync di Mozilla &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/performance-now-2024-experience-europe-web-performance-conference/#pre-evento-performance-sync-di-mozilla&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Il 13 novembre&lt;/strong&gt;, il giorno prima di Performance.now, ho avuto anche il piacere di partecipare a &lt;strong&gt;Performance.Sync&lt;/strong&gt;, un evento organizzato da Mozilla. Durante questa sessione, il mio collega Brian Louis Ramirez ha tenuto una presentazione sul tema &amp;quot;&lt;strong&gt;Finding the needle in the haystack&lt;/strong&gt;&amp;quot; (Trovare il ago nel pagliaio), incentrata sull&#39;identificazione di anomalie nei &lt;strong&gt;dati RUM (Real User Monitoring)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Le intuizioni di Brian su come analizzare efficacemente enormi quantità di dati sulle prestazioni per individuare problemi critici sono state illuminanti e molto pratiche. La partecipazione a Performance.Sync mi ha fornito una comprensione più profonda delle tecniche avanzate di analisi dei dati e ha rafforzato l&#39;importanza di un monitoraggio meticoloso nell&#39;ottimizzazione delle performance web.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/7oWOBJjikH-648.webp 648w, https://andreaverlicchi.eu/img/7oWOBJjikH-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/7oWOBJjikH-648.jpeg 648w, https://andreaverlicchi.eu/img/7oWOBJjikH-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Brian Louis Ramirez sul palco di Performance.sync 2024&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/7oWOBJjikH-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Mesdames et messieurs, &lt;a href=&quot;https://screenspan.net/&quot;&gt;Brian Louis Ramirez&lt;/a&gt; sul palco&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;spunti-raccolti-e-approfondimenti&quot; tabindex=&quot;-1&quot;&gt;Spunti raccolti e approfondimenti &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/performance-now-2024-experience-europe-web-performance-conference/#spunti-raccolti-e-approfondimenti&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Durante la conferenza ho preso alcuni appunti che rileggerò con attenzione, poiché molti di essi mi hanno spinto a pianificare delle attività.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SpeedCurve ha scritto una &lt;a href=&quot;https://www.speedcurve.com/web-performance-guide/&quot;&gt;guida completa sulle web performance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Ottima idea quella di correlare tasso di conversione e INP&lt;/li&gt;
&lt;li&gt;Configurare gli alert solo sui cambiamenti dei KPI principali, non quando cambiano i fattori abilitanti (enabler)&lt;/li&gt;
&lt;li&gt;Suddividere le regressioni in moderate, accettabili e critiche, in base alla percentuale di regressione&lt;/li&gt;
&lt;li&gt;Quando si verifica una regressione, analizzare chi, cosa, quando, dove e perché è accaduta&lt;/li&gt;
&lt;li&gt;~Le immagini caricate in modalità lazy possono essere decodificate in modo asincrono, ma quelle caricate in modalità eager no.~ Discusso, vedi &lt;a href=&quot;https://www.tunetheweb.com/blog/what-does-the-image-decoding-attribute-actually-do/&quot;&gt;cosa fa effettivamente &lt;code&gt;decode=async&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;La nuova funzionalità delle annotazioni nei Chrome DevTools sarà utilissima per me e altri professionisti&lt;/li&gt;
&lt;li&gt;Possiamo usare &lt;a href=&quot;https://crbug.com/new&quot;&gt;crbug.com/new&lt;/a&gt; per segnalare bug al progetto Chromium e richiedere nuove funzionalità&lt;/li&gt;
&lt;li&gt;Gli sviluppatori di Chrome stanno spostando le informazioni dal pannello Performance Insights a quello Performance — ce n&#39;è uno anche per le prestazioni CSS, se si esegue una traccia con l&#39;opzione &amp;quot;Selector stats (slow)&amp;quot; attiva&lt;/li&gt;
&lt;li&gt;I font variabili sono più leggeri solo se si utilizzano due o più variazioni dello stesso font, altrimenti conviene caricare la singola variazione (es. la versione bold per i titoli)&lt;/li&gt;
&lt;li&gt;La scheda CSS overview nei developer tools offre un&#39;idea di quanti elementi della pagina utilizzano determinati font&lt;/li&gt;
&lt;li&gt;C&#39;è un nuovo gruppo di lavoro per l&#39;incremental font transfer, per scaricare solo la porzione di font di cui l&#39;utente ha effettivamente bisogno al momento&lt;/li&gt;
&lt;li&gt;&lt;code&gt;size-adjust&lt;/code&gt; (a livello di box) e &lt;code&gt;font-size-adjust&lt;/code&gt; (a livello di font) sono utili per cercare di renderizzare il font di fallback in modo simile al web font. Ho preso nota di uno strumento chiamato css-size-adjust-tester, che al momento non riesco a trovare, mentre ho trovato il &lt;a href=&quot;https://screenspan.net/fallback/&quot;&gt;generatore di font di fallback di Brian Louis Ramirez&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Google Publisher Tag (GPT) ha una &lt;a href=&quot;https://developers.google.com/publisher-tag/reference#googletag.config.PageSettingsConfig.threadYield&quot;&gt;funzionalità per cedere il controllo al main thread (yield)&lt;/a&gt; per ottimizzare l&#39;INP&lt;/li&gt;
&lt;li&gt;Quando ci sono buchi negli eventi di commit nei dev tools, controllate in altre tracce o caricate la traccia in Perfetto per capire il motivo&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Questi appunti sono stati fondamentali per definire i passaggi successivi e integrare nuove tecniche nel mio flusso di lavoro, oltre che per i miei progetti personali. Condividere queste riflessioni sarà indubbiamente utile per chiunque voglia migliorare le proprie competenze sulle web performance.&lt;/p&gt;
&lt;h2 id=&quot;riflessioni-sull-esperienza&quot; tabindex=&quot;-1&quot;&gt;Riflessioni sull&#39;esperienza &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/performance-now-2024-experience-europe-web-performance-conference/#riflessioni-sull-esperienza&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;img alt=&quot;Partecipanti nelle prime file di performance.now()&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/pWsca6bveI-648.webp&quot; width=&quot;1296&quot; height=&quot;863&quot; srcset=&quot;https://andreaverlicchi.eu/img/pWsca6bveI-648.webp 648w, https://andreaverlicchi.eu/img/pWsca6bveI-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;
	&lt;figcaption&gt;Mi piace sedermi nelle prime file per interagire visivamente con gli speaker&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Partecipare a Performance.now è stata un&#39;esperienza gratificante che ha rafforzato il mio impegno per l&#39;eccellenza nelle performance web. Il mix di &lt;strong&gt;contenuti di alto livello, speaker esperti e una community vibrante&lt;/strong&gt; rende questo evento imperdibile per chiunque operi in questa nicchia. Non vedo l&#39;ora di applicare le conoscenze acquisite e di contribuire ulteriormente al dialogo continuo nel nostro settore.&lt;/p&gt;
&lt;p&gt;Se avete la passione per le web performance e desiderate migliorare le vostre competenze, vi consiglio caldamente di partecipare a Performance.now. Non è solo una conferenza: è un incontro tra le menti più brillanti dedicate a spingere i limiti di ciò che è possibile sul web.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Non esitate a contattarmi se avete domande sulla conferenza o sulle web performance in generale!&lt;/em&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Come usare Google Meet con due schermi: separare i contenuti condivisi e i volti dei partecipanti</title>
		<link href="https://andreaverlicchi.eu/it/blog/google-meet-two-screens-separate-content-faces/"/>
		<updated>2024-11-06T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/google-meet-two-screens-separate-content-faces/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/JCP9CiWzL1-509.webp 509w, https://andreaverlicchi.eu/img/JCP9CiWzL1-1018.webp 1018w&quot; sizes=&quot;509px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/JCP9CiWzL1-509.png 509w, https://andreaverlicchi.eu/img/JCP9CiWzL1-1018.png 1018w&quot; sizes=&quot;509px&quot;&gt;&lt;img alt=&quot;Pronto a partecipare? Andrea Verlicchi e Andrea Verlicchi sono in questa chiamata. Cambia qui; Altri modi per partecipare ⬇&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/JCP9CiWzL1-509.png&quot; width=&quot;1018&quot; height=&quot;569&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;La schermata di benvenuto di Google Meet.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;In Google Meet, se si lavora con due schermi, potrebbe essere utile tenere i contenuti condivisi su uno schermo e i volti dei partecipanti sull&#39;altro. Questa configurazione permette un maggiore coinvolgimento durante la riunione, rendendo più facile concentrarsi sui volti dei partecipanti, sulla chat e sulle altre interazioni, pur continuando a tenere d&#39;occhio la presentazione o il contenuto condiviso. Ecco come fare utilizzando la &lt;em&gt;modalità Companion&lt;/em&gt; di Google Meet e pochi passaggi manuali.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;👀 &lt;strong&gt;L&#39;attesa è finita&lt;/strong&gt;!!! Questo non è più necessario a partire da marzo 2026, perché Google ha &lt;a href=&quot;https://releasebot.io/updates/google/google-meet#:~:text=Move%20shared%20content%20in%20Google%20Meet%20to%20a%20separate%20window%20with%20the%20%E2%80%9COpen%20in%20new%20window%E2%80%9D%20option&quot;&gt;rilasciato&lt;/a&gt; la funzione per portare il contenuto condiviso in una nuova finestra! 🥳
Lascio l&#39;articolo qui perché è un buon esempio di come usare la &lt;em&gt;modalità Companion&lt;/em&gt; e potrebbe essere utile per qualcuno.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;guida-passo-passo-all-uso-della-modalita-companion&quot; tabindex=&quot;-1&quot;&gt;Guida passo-passo all&#39;uso della modalità Companion &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-meet-two-screens-separate-content-faces/#guida-passo-passo-all-uso-della-modalita-companion&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;L&#39;uso della &lt;em&gt;modalità Companion&lt;/em&gt; consente di accedere nuovamente a una riunione di Google Meet da una seconda scheda o finestra senza duplicare l&#39;audio, permettendo di configurare ciascuna finestra singolarmente. Ecco come la imposto io:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Impostare il layout per i volti dei partecipanti&lt;/strong&gt;&lt;br&gt;
Nella finestra principale della riunione, cliccate sul menu con i tre puntini &lt;code&gt;...&lt;/code&gt; (altre opzioni) e andate su &lt;strong&gt;Modifica layout&lt;/strong&gt;. Scegliete &lt;strong&gt;Griglia&lt;/strong&gt; (Tiled) per assicurarvi che i volti dei partecipanti siano visibili in una griglia.&lt;/p&gt;
 &lt;figure&gt;
     &lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/zx39sVPAf7-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Modifica layout. La selezione viene salvata per le riunioni future. Automatico; Griglia; In primo piano; Barra laterale. Riquadri; Numero massimo di riquadri da visualizzare, a seconda delle dimensioni della finestra. Nascondi i riquadri senza video.&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/zx39sVPAf7-648.png&quot; width=&quot;648&quot; height=&quot;888&quot;&gt;&lt;/picture&gt;
     &lt;figcaption&gt;La schermata di Google Meet per cambiare il layout&lt;/figcaption&gt;
 &lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Minimizzare la presentazione nella finestra principale&lt;/strong&gt;&lt;br&gt;
Se la presentazione è bloccata in primo piano, sbloccatela passandoci sopra con il mouse e cliccando sull&#39;icona della puntina (unpin). Questo ridurrà le dimensioni della presentazione e ingrandirà i volti dei partecipanti, assicurando che il vostro focus principale in questa finestra rimanga sulle persone e non sul contenuto.&lt;/p&gt;
 &lt;figure&gt;
     &lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/6jdKG95u7c-436.webp 436w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Icone per sbloccare, silenziare, rimuovere dalla chiamata. Il tooltip mostra &#39;Sblocca&#39;.&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/6jdKG95u7c-436.png&quot; width=&quot;436&quot; height=&quot;270&quot;&gt;&lt;/picture&gt;
     &lt;figcaption&gt;Questa è l&#39;icona per sbloccare il contenuto presentato.&lt;/figcaption&gt;
 &lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Duplicare la scheda di Google Meet&lt;/strong&gt;&lt;br&gt;
Fate clic con il tasto destro sulla scheda di Google Meet e selezionate &lt;strong&gt;Duplica&lt;/strong&gt;. Questa nuova scheda verrà utilizzata esclusivamente per visualizzare il contenuto condiviso.&lt;/p&gt;
 &lt;figure&gt;
     &lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/bA21waIEKV-341.webp 341w, https://andreaverlicchi.eu/img/bA21waIEKV-682.webp 682w&quot; sizes=&quot;341px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/bA21waIEKV-341.png 341w, https://andreaverlicchi.eu/img/bA21waIEKV-682.png 682w&quot; sizes=&quot;341px&quot;&gt;&lt;img alt=&quot;...&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/bA21waIEKV-341.png&quot; width=&quot;682&quot; height=&quot;676&quot;&gt;&lt;/picture&gt;
     &lt;figcaption&gt;Ecco il menu a discesa per duplicare una scheda di Chrome&lt;/figcaption&gt;
 &lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Abilitare la modalità Companion nella scheda duplicata&lt;/strong&gt;&lt;br&gt;
Nella scheda duplicata, scegliete &lt;strong&gt;Usa modalità Companion&lt;/strong&gt;. La modalità Companion vi farà partecipare nuovamente alla riunione ma senza audio, evitando così fastidiosi echi o fischi. Questa seconda finestra servirà esclusivamente per la visualizzazione dei contenuti.&lt;/p&gt;
 &lt;figure&gt;
     &lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/wmjELm1U7i-512.webp 512w, https://andreaverlicchi.eu/img/wmjELm1U7i-1024.webp 1024w&quot; sizes=&quot;512px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/wmjELm1U7i-512.png 512w, https://andreaverlicchi.eu/img/wmjELm1U7i-1024.png 1024w&quot; sizes=&quot;512px&quot;&gt;&lt;img alt=&quot;Pronto a partecipare? Andrea Verlicchi e Andrea Verlicchi sono in questa chiamata. Cambia qui; Presenta; Usa la modalità Companion; Mostra meno opzioni ⬆️&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/wmjELm1U7i-512.png&quot; width=&quot;1024&quot; height=&quot;833&quot;&gt;&lt;/picture&gt;
     &lt;figcaption&gt;La modalità Companion si trova proprio lì, evidenziata in blu.&lt;/figcaption&gt;
 &lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Spostare la scheda in modalità Companion in una nuova finestra e posizionarla sullo schermo principale&lt;/strong&gt;&lt;br&gt;
Trascinate la scheda in modalità Companion in una finestra separata e spostatela sullo schermo principale dove volete visualizzare il contenuto condiviso. Ora avrete la riunione principale con i volti dei partecipanti su uno schermo e il contenuto in modalità Companion sull&#39;altro.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Migliorare la finestra in modalità Companion con il mio bookmarklet per lo schermo intero reale di Google Meet&lt;/strong&gt;&lt;br&gt;
Nella finestra in &lt;em&gt;modalità Companion&lt;/em&gt;, potete usare il mio bookmarklet &lt;a href=&quot;https://github.com/verlok/google-meet-true-full-screen/&quot;&gt;Google Meet true full screen&lt;/a&gt; per attivare una modalità a schermo intero reale. In questo modo, il contenuto condiviso riempirà lo schermo senza elementi dell&#39;interfaccia utente superflui, rendendo più facile concentrarsi sulla presentazione.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Passaggio bonus&lt;/strong&gt; Se attivate il Picture-in-Picture (PIP) nella finestra principale di Google Meet, è persino possibile portare i volti dei partecipanti davanti al contenuto presentato da qualcun altro, proprio come si può fare con Zoom.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;perche-questa-configurazione-funziona&quot; tabindex=&quot;-1&quot;&gt;Perché questa configurazione funziona &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-meet-two-screens-separate-content-faces/#perche-questa-configurazione-funziona&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Questa configurazione mantiene i volti dei partecipanti, la chat e i controlli accessibili nella finestra principale, riservando un secondo schermo esclusivamente per i contenuti. Offre un&#39;esperienza più immersiva ed è un ottimo modo per aggirare le attuali limitazioni dell&#39;interfaccia utente di Google Meet.&lt;/p&gt;
&lt;h2 id=&quot;considerazioni-finali&quot; tabindex=&quot;-1&quot;&gt;Considerazioni finali &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-meet-two-screens-separate-content-faces/#considerazioni-finali&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Sì, è un processo un po&#39; manuale, ma finché Google non migliorerà il supporto per i doppi schermi, questi passaggi rappresentano il modo più efficace per gestire gli elementi visivi della riunione su più schermi. Questa configurazione è particolarmente utile per conferenze virtuali o riunioni con un alto livello di interazione, poiché mantiene completamente visibili sia la presentazione che le persone che vi partecipano.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Provatela e fatemi sapere come vi trovate! Se avete suggerimenti per snellire il processo, non esitate a condividerli.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Modalità a schermo intero reale per i contenuti condivisi su Google Meet</title>
		<link href="https://andreaverlicchi.eu/it/blog/true-full-screen-google-meet-bookmarklet/"/>
		<updated>2024-11-05T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/true-full-screen-google-meet-bookmarklet/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Z2bUG-5AUo-648.webp 648w, https://andreaverlicchi.eu/img/Z2bUG-5AUo-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/Z2bUG-5AUo-648.png 648w, https://andreaverlicchi.eu/img/Z2bUG-5AUo-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Google Meet a schermo intero reale, senza la barra superiore e i controlli&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/Z2bUG-5AUo-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Google Meet a schermo intero reale, finalmente!&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Passando molto tempo su Google Meet, mi sono spesso scontrato con la frustrazione di non poter visualizzare i contenuti condivisi in modalità a schermo intero reale. Massimizzare lo spazio sullo schermo è fondamentale, specialmente quando si analizza del codice complesso o presentazioni di design dettagliate. Tuttavia, per qualche motivo, Meet limita le opzioni di schermo intero lasciando visibili i bordi e gli elementi dell&#39;interfaccia utente, il che può essere fonte di distrazione.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;👀 &lt;strong&gt;L&#39;attesa è finita&lt;/strong&gt;!!! Questo non è più necessario a partire da marzo 2026, perché Google ha &lt;a href=&quot;https://releasebot.io/updates/google/google-meet#:~:text=Move%20shared%20content%20in%20Google%20Meet%20to%20a%20separate%20window%20with%20the%20%E2%80%9COpen%20in%20new%20window%E2%80%9D%20option&quot;&gt;rilasciato&lt;/a&gt; la funzione per portare il contenuto condiviso in una nuova finestra! 🥳
Lascio l&#39;articolo qui perché è un buon esempio di come creare un bookmarklet e potrebbe essere utile per qualcuno.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Mi sono stancato di aspettare che Google fornisse una soluzione, così ho deciso di crearmene una da solo. Ho creato un bookmarklet che permette di visualizzare i contenuti condivisi a schermo intero reale su Google Meet, rimuovendo gli elementi estranei e massimizzando lo spazio utile sullo schermo.&lt;/p&gt;
&lt;p&gt;Date un&#39;occhiata e aggiungetelo al vostro browser qui:&lt;/p&gt;
&lt;p&gt;👉 &lt;a href=&quot;https://github.com/verlok/google-meet-true-full-screen/tree/main&quot;&gt;Google Meet True Full-Screen Bookmarklet su GitHub&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Lì troverete la procedura per aggiungere il bookmarklet al vostro browser e, una volta aggiunto, potrete attivare la modalità a schermo intero reale con un solo clic.&lt;/p&gt;
&lt;p&gt;Questo semplice script mira a migliorare l&#39;esperienza durante i meeting mantenendo il focus sui contenuti che contano.
Fatemi sapere se lo trovate utile, o se ci sono modifiche o funzionalità che vi piacerebbe aggiungere.&lt;/p&gt;
&lt;p&gt;Buona visione a schermo intero!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Il dibattito sul lavoro da remoto: la mia visione per trovare un equilibrio</title>
		<link href="https://andreaverlicchi.eu/it/blog/remote-work-debate-perfect-balance/"/>
		<updated>2024-10-20T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/remote-work-debate-perfect-balance/</id>
		<content type="html">&lt;img alt=&quot;Un&#39;illustrazione di una persona che lavora da remoto in un comodo ufficio a casa, circondata da piante e oggetti personali, con un laptop aperto.&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/6DbJ6HsspB-648.webp&quot; width=&quot;1296&quot; height=&quot;740&quot; srcset=&quot;https://andreaverlicchi.eu/img/6DbJ6HsspB-648.webp 648w, https://andreaverlicchi.eu/img/6DbJ6HsspB-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;
&lt;p&gt;Dopo quasi tre anni di lavoro completamente da remoto, sei anni di &amp;quot;smart-working&amp;quot; (due da casa, tre in ufficio) e più di 15 anni di lavoro in ufficio, ho acquisito una buona prospettiva sul dibattito relativo al lavoro da remoto. Sebbene sostenga molti dei vantaggi del lavoro da casa, ne riconosco anche gli svantaggi, e penso che esista una via di mezzo ideale.&lt;/p&gt;
&lt;h2 id=&quot;i-vantaggi-del-lavoro-da-remoto&quot; tabindex=&quot;-1&quot;&gt;I vantaggi del lavoro da remoto &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/remote-work-debate-perfect-balance/#i-vantaggi-del-lavoro-da-remoto&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il lavoro da remoto offre chiari vantaggi. Prima di tutto, è efficace: consente una maggiore produttività, meno distrazioni e una migliore concentrazione quando si ha la giusta configurazione, che si tratti di uno spazio isolato in casa o di una scrivania in un coworking. Per i dipendenti c&#39;è anche il vantaggio della flessibilità. Si ha la libertà di organizzare i propri orari più facilmente in base agli impegni personali e alle proprie preferenze. Anche dal punto di vista economico è una vittoria: nessun costo di pendolarismo, nessuna necessità di pranzare fuori ogni giorno.&lt;/p&gt;
&lt;h2 id=&quot;l-elemento-umano-cosa-ci-perdiamo&quot; tabindex=&quot;-1&quot;&gt;L&#39;elemento umano: cosa ci perdiamo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/remote-work-debate-perfect-balance/#l-elemento-umano-cosa-ci-perdiamo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ma il lavoro da remoto non ha solo lati positivi. Uno dei maggiori svantaggi è l&#39;isolamento che può portare con sé. È facile compensare questo aspetto rimanendo attivi, andando in palestra o vedendosi con gli amici. Tuttavia, nulla può sostituire gli scambi spontanei che avvengono con i colleghi quando si condivide uno spazio di lavoro. Queste interazioni informali possono far nascere nuove idee e contribuire a rafforzare lo spirito di squadra.&lt;/p&gt;
&lt;p&gt;Un esempio personale: proprio giovedì scorso ero ad Amburgo per un evento presso l&#39;ufficio dell&#39;azienda. Durante una pausa, ho fatto una chiacchierata informale con una collega, una studentessa lavoratrice, e ho scoperto che stava preparando la sua tesi su un argomento direttamente correlato a un progetto su cui sto lavorando. Quella preziosa connessione non ci sarebbe stata senza l&#39;interazione di persona.&lt;/p&gt;
&lt;p&gt;C&#39;è qualcosa di unico nei legami che si creano lavorando fianco a fianco per molte ore. In molti casi, lavorando a tempo pieno in ufficio, si passa più tempo con i colleghi che con la propria famiglia. Questo è particolarmente vero per i piccoli team, dove queste relazioni possono essere così forti da durare per anni — legami* che restano solidi anche quando si cambia lavoro.&lt;/p&gt;
&lt;p&gt;*Marco, Giorgio, Alberto, David e Tommy, se state leggendo questo post, vi sto pensando.&lt;/p&gt;
&lt;h2 id=&quot;trovare-l-equilibrio-un-approccio-ibrido&quot; tabindex=&quot;-1&quot;&gt;Trovare l&#39;equilibrio: un approccio ibrido &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/remote-work-debate-perfect-balance/#trovare-l-equilibrio-un-approccio-ibrido&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Nella mia esperienza, la configurazione ideale è un approccio ibrido. Lavorare da casa la maggior parte del tempo, ma con la flessibilità di andare in ufficio quando necessario — ad esempio per sessioni di brainstorming, progetti collaborativi o riunioni importanti.&lt;/p&gt;
&lt;p&gt;Ritengo inoltre che le aziende dovrebbero organizzare regolarmente eventi di persona — come workshop o attività di team building — almeno quattro volte all&#39;anno, per mantenere vivo il senso di connessione e di scopo condiviso.&lt;/p&gt;
&lt;p&gt;Questo modello trova il giusto equilibrio tra autonomia e collaborazione, assicurandoci che, pur godendo della flessibilità del lavoro da remoto, non si perdano le preziose relazioni interpersonali che alimentano l&#39;innovazione e il cameratismo all&#39;interno di un team.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Talk: Come ho reso il web più reattivo — casi reali di ottimizzazione dell&#39;INP</title>
		<link href="https://andreaverlicchi.eu/it/blog/how-i-made-the-web-more-responsive--debug-avoid-slow-interaction-next-paint-inp/"/>
		<updated>2024-09-17T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/how-i-made-the-web-more-responsive--debug-avoid-slow-interaction-next-paint-inp/</id>
		<content type="html">&lt;p&gt;A partire da maggio 2024 ho iniziato a tenere talk a conferenze e meetup su come migliorare la reattività del web. I miei interventi si concentrano su come fare il debug e prevenire le interazioni lente, attingendo alla mia esperienza di audit dell&#39;Interaction to Next Paint (INP) su decine di siti web di clienti.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/FDb4aKLIVsI?si=WNNwr8DcyRAplbKB&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; referrerpolicy=&quot;strict-origin-when-cross-origin&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Dopo una spiegazione iniziale dell&#39;INP, mostro come fare il debug delle interazioni lente utilizzando sia Chrome DevTools sia i dati RUM (Real User Monitoring). Illustro poi tre errori comuni che ho riscontrato durante l&#39;audit dell&#39;INP su decine di siti web e spiego come evitarli per garantire interazioni scattanti per l&#39;utente e mantenere l&#39;INP sotto i 200 millisecondi.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://docs.google.com/presentation/d/1kSHr9mEN2Q4Nyis8uWvxoA3_pqOIywr3TXCLeO_-4qA/edit&quot;&gt;📽️ Slide&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;we-love-speed-nantes-17-settembre-2024&quot; tabindex=&quot;-1&quot;&gt;We Love Speed, Nantes 🇫🇷 - &lt;time datetime=&quot;2024-07-17&quot;&gt;17 Settembre 2024&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-i-made-the-web-more-responsive--debug-avoid-slow-interaction-next-paint-inp/#we-love-speed-nantes-17-settembre-2024&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/rpboOrNxxf-648.webp 648w, https://andreaverlicchi.eu/img/rpboOrNxxf-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/rpboOrNxxf-648.jpeg 648w, https://andreaverlicchi.eu/img/rpboOrNxxf-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi parla a We Love Speed, Nantes, 2024&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/rpboOrNxxf-648.jpeg&quot; width=&quot;1296&quot; height=&quot;863&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Sul palco di We Love Speed 2024, Nantes&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Il titolo del talk era &amp;quot;How I made the web more responsive - real-world case studies of INP optimizations&amp;quot;, in francese &amp;quot;Comment j’ai rendu le web plus réactif — études de cas concrets d’optimisations d’INP&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=FDb4aKLIVsI&quot;&gt;📺 Video&lt;/a&gt; - &lt;a href=&quot;https://www.welovespeed.com/en/2024/talks/how-i-made-the-web-more-responsive/&quot;&gt;Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;we-make-future-bologna-14-giugno-2024&quot; tabindex=&quot;-1&quot;&gt;We Make Future, Bologna 🇮🇹 - &lt;time datetime=&quot;2024-06-14&quot;&gt;14 Giugno 2024&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-i-made-the-web-more-responsive--debug-avoid-slow-interaction-next-paint-inp/#we-make-future-bologna-14-giugno-2024&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/YKQw5uBAIG-648.webp 648w, https://andreaverlicchi.eu/img/YKQw5uBAIG-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/YKQw5uBAIG-648.jpeg 648w, https://andreaverlicchi.eu/img/YKQw5uBAIG-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi parla sul palco Coding Front-end di We Make Future Bologna. La slide mostra il browser che visita un sito web, i developer tools del browser aperti sul pannello Performance, e 7 passaggi descritti a destra. 1: Emulate device, 2: Performance options, 3: Slowdown the CPU, 4: Start recording, 5: Click around, 6: Type around, 7: Stop recording&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/YKQw5uBAIG-648.jpeg&quot; width=&quot;1296&quot; height=&quot;835&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Sul palco Coding Front-end di WMF 2024: come fare il debug dell&#39;INP, alla vecchia maniera.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Il titolo del talk, in italiano, era &amp;quot;Migliorare la reattività del web — Guida pratica per debug e prevenzione delle interazioni lente&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=OQ8djUCFHTk&quot;&gt;📺 Video&lt;/a&gt; - &lt;a href=&quot;https://www.wemakefuture.it/s/65e6dde7acc90ad8ebbfff17/#sala=CodingFrontend%7Ccodingfrontend&quot;&gt;Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;google-developer-group-madrid-4-giugno-2024&quot; tabindex=&quot;-1&quot;&gt;Google Developer Group, Madrid 🇪🇸 - &lt;time datetime=&quot;2024-06-04&quot;&gt;4 Giugno 2024&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-i-made-the-web-more-responsive--debug-avoid-slow-interaction-next-paint-inp/#google-developer-group-madrid-4-giugno-2024&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/hthSTqoJ5y-648.webp 648w, https://andreaverlicchi.eu/img/hthSTqoJ5y-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/hthSTqoJ5y-648.jpeg 648w, https://andreaverlicchi.eu/img/hthSTqoJ5y-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi parla a GDG Madrid (presso Celonis), alcune persone nelle prime file, la slide mostra la parte di input delay della misurazione dell&#39;INP nel thread principale del browser&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/hthSTqoJ5y-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Presentazione al GDG Madrid, in cui mostro la prima sotto-parte dell&#39;INP: l&#39;Input Delay.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Il titolo del talk in spagnolo era: &amp;quot;Hagamos que la web sea mas responsive en 2024&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gdg.community.dev/events/details/google-gdg-madrid-presents-hagamos-que-la-web-sea-mas-responsive-en-2024/&quot;&gt;Evento GDG Madrid&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;bologna-js-bologna-22-maggio-2024&quot; tabindex=&quot;-1&quot;&gt;Bologna JS, Bologna 🇮🇹 - &lt;time datetime=&quot;2024-05-22&quot;&gt;22 Maggio 2024&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-i-made-the-web-more-responsive--debug-avoid-slow-interaction-next-paint-inp/#bologna-js-bologna-22-maggio-2024&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/HKEEow_XEy-648.webp 648w, https://andreaverlicchi.eu/img/HKEEow_XEy-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/HKEEow_XEy-648.jpeg 648w, https://andreaverlicchi.eu/img/HKEEow_XEy-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi parla al Bologna JS, alcune persone nelle prime file, la slide mostra la parola &#39;Conclusion&#39;&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/HKEEow_XEy-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Al meetup di Bologna JS. Questa è l&#39;unica foto che ho 🤷‍♂️. Praticamente la conclusione.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://youtube.com/live/ibZ1y3LxKKg?feature=share&quot;&gt;📺 Video&lt;/a&gt; · &lt;a href=&quot;https://www.meetup.com/bologna-js-meetup/events/300919249/&quot;&gt;Pagina dell&#39;evento su Meetup&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;google-developer-group-bologna-01-ottobre-2024&quot; tabindex=&quot;-1&quot;&gt;Google Developer Group, Bologna 🇮🇹 - &lt;time datetime=&quot;2024-10-01&quot;&gt;01 Ottobre 2024&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-i-made-the-web-more-responsive--debug-avoid-slow-interaction-next-paint-inp/#google-developer-group-bologna-01-ottobre-2024&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/-QghAZtl_M-648.webp 648w, https://andreaverlicchi.eu/img/-QghAZtl_M-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/-QghAZtl_M-648.jpeg 648w, https://andreaverlicchi.eu/img/-QghAZtl_M-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi sul palco del Phygital Hub (Gellify)&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/-QghAZtl_M-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io che parlo sul &quot;palco&quot; al Phygital Hub (Gellify)&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Titolo: &amp;quot;Come ho reso il web più reattivo - Guida pratica di come trovare ed evitare le interazioni lente.&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gdg.community.dev/events/details/google-gdg-bologna-presents-come-ho-reso-il-web-piu-reattivo/&quot;&gt;Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;devromagna-faenza-26-settembre-2024&quot; tabindex=&quot;-1&quot;&gt;DevRomagna, Faenza 🇮🇹 - &lt;time datetime=&quot;2024-09-26&quot;&gt;26 Settembre 2024&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-i-made-the-web-more-responsive--debug-avoid-slow-interaction-next-paint-inp/#devromagna-faenza-26-settembre-2024&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/n-9_MSNZXX-648.webp 648w, https://andreaverlicchi.eu/img/n-9_MSNZXX-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/n-9_MSNZXX-648.jpeg 648w, https://andreaverlicchi.eu/img/n-9_MSNZXX-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi sul palco di DevRomagna, Faenza&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/n-9_MSNZXX-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io che parlo sul palco di DevRomagna, Faenza&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Titolo: &amp;quot;Come ho reso il web più reattivo - Guida pratica di come trovare ed evitare le interazioni lente.&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://meetu.ps/e/NtXTj/zKMHn/i&quot;&gt;Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Le mie funzioni preferite di iOS 18: una svolta per gli utenti multilingue (e non solo)</title>
		<link href="https://andreaverlicchi.eu/it/blog/favourite-features-ios-18/"/>
		<updated>2024-09-13T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/favourite-features-ios-18/</id>
		<content type="html">&lt;p&gt;Con ogni nuova versione di iOS, non vedo l&#39;ora di esplorare le ultime funzionalità offerte da Apple. iOS 18 ha introdotto diversi cambiamenti, alcuni piccoli e discreti, altri più profondi, che hanno migliorato notevolmente la mia esperienza d&#39;uso. Ecco le mie nuove funzioni preferite in iOS 18 e perché penso che rappresentino una svolta.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/x4O6m0ssMy-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Il selettore della tastiera di iOS 18 che mostra diversi set di tastiere: italiano e inglese, portoghese e francese, spagnolo e tedesco&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/x4O6m0ssMy-648.png&quot; width=&quot;648&quot; height=&quot;535&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Il selettore della tastiera di iOS 18 che mostra diversi set di tastiere: italiano e inglese, portoghese e francese, spagnolo e tedesco&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;1-tastiere-bilingue-un-esperienza-multilingue-fluida&quot; tabindex=&quot;-1&quot;&gt;1. Tastiere bilingue: un&#39;esperienza multilingue fluida &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/favourite-features-ios-18/#1-tastiere-bilingue-un-esperienza-multilingue-fluida&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Uno dei miei aggiornamenti preferiti in assoluto è la nuova funzionalità della tastiera che mi consente di digitare in più lingue senza cambiare manualmente la lingua di input. È molto meglio così! In sostanza, iOS 18 offre tastiere bilingue, quindi posso scrivere messaggi come:&lt;/p&gt;
&lt;p&gt;“Guten Tag! Buenos días! Alles gut? Sí, muy bien! Bom dia! Bonjour! Tudo beleza? Oui, ça va très bien!”&lt;/p&gt;
&lt;p&gt;E la parte migliore? Non ho bisogno di cambiare il layout della tastiera ogni volta che cambio lingua. Si tratta di un miglioramento enorme, soprattutto per chi passa continuamente da una lingua all&#39;altra come me. È una piccola funzione che aggiunge tantissima fluidità alle conversazioni multilingue.&lt;/p&gt;
&lt;h2 id=&quot;2-dettatura-migliorata-piu-veloce-e-intelligente&quot; tabindex=&quot;-1&quot;&gt;2. Dettatura migliorata: più veloce e intelligente &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/favourite-features-ios-18/#2-dettatura-migliorata-piu-veloce-e-intelligente&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;“Ciao, sto provando la nuova funzione di dettatura su iPhone 18. Sembra avere la punteggiatura automatica anche in italiano ora. A che ora hai detto che partiamo oggi?”&lt;/p&gt;
&lt;p&gt;Sì, la punteggiatura automatica è arrivata! Si tratta di un aggiornamento semplice ma estremamente utile, che mi fa risparmiare un sacco di tempo in fase di modifica. Un piccolo consiglio, però: per dettare in inglese, assicuratevi di avere abilitata la dettatura in inglese, poiché l&#39;impostazione predefinita in italiano riconoscerà solo parole inglesi elementari. È un piccolo ostacolo, ma il miglioramento generale della dettatura è innegabile.&lt;/p&gt;
&lt;h2 id=&quot;3-schermata-home-centro-di-controllo-e-sfondi-migliorati&quot; tabindex=&quot;-1&quot;&gt;3. Schermata Home, Centro di Controllo e sfondi migliorati &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/favourite-features-ios-18/#3-schermata-home-centro-di-controllo-e-sfondi-migliorati&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;iOS 18 ha fatto grandi passi avanti anche nella personalizzazione. Ora la gestione della schermata home e del centro di controllo è molto più flessibile. È possibile posizionare liberamente le icone delle app sulla schermata home senza la rigida griglia di una volta. Inoltre, la gestione degli sfondi è diventata più intuitiva, rendendo più facile cambiare e organizzare i wallpaper.&lt;/p&gt;
&lt;h2 id=&quot;4-aggiornamenti-a-note-promemoria-e-calendario&quot; tabindex=&quot;-1&quot;&gt;4. Aggiornamenti a Note, Promemoria e Calendario &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/favourite-features-ios-18/#4-aggiornamenti-a-note-promemoria-e-calendario&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Per chi di noi usa quotidianamente le app di produttività integrate, iOS 18 ha introdotto alcune utili novità. In Note ora ci sono le sezioni comprimibili, mentre in Promemoria la funzione degli elenchi intelligenti rende la gestione delle attività un gioco da ragazzi. L&#39;app Calendario ha introdotto una nuova vista mensile che rende la pianificazione ancora più efficiente. Si tratta di piccoli aggiornamenti incrementali, ma preziosi per rimanere organizzati.&lt;/p&gt;
&lt;h2 id=&quot;5-pagine-web-lette-ad-alta-voce-la-vera-svolta&quot; tabindex=&quot;-1&quot;&gt;5. Pagine web lette ad alta voce (la vera svolta) &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/favourite-features-ios-18/#5-pagine-web-lette-ad-alta-voce-la-vera-svolta&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Questa potrebbe essere la killer feature di iOS 18. Ora è possibile farsi leggere ad alta voce intere pagine web o articoli, anche con lo schermo spento. Siri ora offre controlli per riproduzione, pausa e velocità di lettura, rendendo il tutto incredibilmente comodo. Prima mi affidavo a Microsoft Edge per questo, ma ora Siri è in grado di gestirlo, almeno per i contenuti in italiano (visto che uso Siri in italiano). Per gli articoli in inglese probabilmente continuerò a usare Edge per ora, ma questa funzione è una fantastica aggiunta per la navigazione a mani libere.&lt;/p&gt;
&lt;h2 id=&quot;6-una-nuova-app-password-per-una-gestione-sicura&quot; tabindex=&quot;-1&quot;&gt;6. Una nuova app Password per una gestione sicura &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/favourite-features-ios-18/#6-una-nuova-app-password-per-una-gestione-sicura&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;iOS 18 introduce anche una nuova app Password, che consente di gestire password, passkey e codici di autenticazione a due fattori in un unico posto. È uno strumento utile per chi non utilizza già un gestore di password di terze parti. Personalmente, continuerò a usare KeePass e KeePassX perché ho bisogno di condividere alcune password con dispositivi non Apple e non voglio rischiare di rimanere bloccato fuori da tutto se dovessi perdere l&#39;accesso al mio Apple ID.&lt;/p&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/favourite-features-ios-18/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Queste sono le mie funzioni preferite che hanno reso iOS 18 un vero piacere da usare. Con una digitazione multilingue più fluida, una dettatura più intelligente e una maggiore personalizzazione, Apple ha davvero fatto un salto di qualità. E non dimentichiamo la comodità di farsi leggere le pagine web da Siri o il nuovo gestore di password integrato. iOS 18 si presenta come una solida evoluzione che migliora le attività quotidiane, rendendo la vita un po&#39; più semplice.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Mitigare il CLS causato da banner promozionali: una soluzione pratica</title>
		<link href="https://andreaverlicchi.eu/it/blog/mitigating-cls-caused-by-promotional-banners/"/>
		<updated>2024-08-26T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/mitigating-cls-caused-by-promotional-banners/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/a9Yij_7xm3-648.webp 648w, https://andreaverlicchi.eu/img/a9Yij_7xm3-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/a9Yij_7xm3-648.png 648w, https://andreaverlicchi.eu/img/a9Yij_7xm3-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;La home page di un sito web con un banner promozionale in alto che spinge verso il basso il contenuto sottostante&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/a9Yij_7xm3-648.png&quot; width=&quot;1296&quot; height=&quot;733&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Un sito web con un banner promozionale in alto che spinge verso il basso il contenuto sottostante&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Il &lt;strong&gt;Cumulative Layout Shift (CLS)&lt;/strong&gt; è una metrica Core Web Vital che misura la stabilità visiva. Si verifica quando il contenuto di una pagina web si sposta in modo imprevisto, causando spesso frustrazione negli utenti.&lt;/p&gt;
&lt;p&gt;Una causa comune di CLS è l&#39;iniezione di un &lt;strong&gt;banner promozionale nella parte superiore della pagina&lt;/strong&gt; dopo che il contenuto principale è già stato caricato. Questo spinge verso il basso gli altri elementi della pagina, portando a una pessima esperienza utente. Sfortunatamente, questo esito è un problema molto comune che si verifica nei siti web su cui ho lavorato o per cui ho fatto consulenza.&lt;/p&gt;
&lt;p&gt;In questo post, esploreremo un metodo per mitigare il CLS riservando spazio per un banner promozionale tramite il session storage. Questo approccio assicura che il banner non causi spostamenti di layout nei successivi caricamenti di pagina, offrendo un&#39;esperienza più stabile e intuitiva per l&#39;utente.&lt;/p&gt;
&lt;h2 id=&quot;il-problema&quot; tabindex=&quot;-1&quot;&gt;Il problema &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/mitigating-cls-caused-by-promotional-banners/#il-problema&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Nello scenario descritto in precedenza, la logica per determinare se mostrare o meno il banner viene eseguita tramite JavaScript, spesso dopo che il contenuto della pagina è già visibile. Ciò comporta uno spostamento del layout, in cui tutto il contenuto al di sotto del banner viene improvvisamente spinto verso il basso, causando un&#39;esperienza utente fastidiosa.&lt;/p&gt;
&lt;h2 id=&quot;la-soluzione&quot; tabindex=&quot;-1&quot;&gt;La soluzione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/mitigating-cls-caused-by-promotional-banners/#la-soluzione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Per risolvere questo problema, possiamo usare &lt;code&gt;sessionStorage&lt;/code&gt; per ricordare il contenuto e lo stato del banner durante la sessione dell&#39;utente. In questo modo, possiamo iniettare il contenuto del banner immediatamente al caricamento della pagina, evitando qualsiasi spostamento di layout. Se l&#39;utente ha chiuso il banner, ci assicuriamo che rimanga nascosto per il resto della sessione, in modo che non venga mostrato al caricamento successivo.&lt;/p&gt;
&lt;p&gt;Ecco come possiamo implementarlo:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Verificare se il banner è stato precedentemente chiuso&lt;/strong&gt;:&lt;br&gt;Per prima cosa controlliamo se l&#39;utente ha chiuso il banner nella sessione corrente. In tal caso, non lo mostriamo di nuovo.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Iniettare il contenuto del banner&lt;/strong&gt;:&lt;br&gt;Se il banner non è stato chiuso e c&#39;è del contenuto salvato nel session storage, lo iniettiamo nella pagina il prima possibile. Questo evita che il layout si sposti quando il banner viene effettivamente caricato.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Salvare il contenuto del banner&lt;/strong&gt;:&lt;br&gt;Quando il contenuto promozionale viene recuperato per la prima volta, lo salviamo nel session storage. Questo ci consente di riutilizzarlo nei successivi caricamenti di pagina senza causare alcuno spostamento di layout.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Gestire la chiusura del banner&lt;/strong&gt;:&lt;br&gt;Se l&#39;utente chiude il banner, impostiamo un flag nel session storage per assicurarci che non ricompaia durante la stessa sessione.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;implementazione&quot; tabindex=&quot;-1&quot;&gt;Implementazione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/mitigating-cls-caused-by-promotional-banners/#implementazione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Trovate qui il &lt;a href=&quot;https://github.com/verlok/cls-issue-promotional-banner-mitigation/&quot;&gt;repository GitHub&lt;/a&gt; con il codice e la &lt;a href=&quot;https://verlok.github.io/cls-issue-promotional-banner-mitigation/&quot;&gt;live demo&lt;/a&gt; su GitHub Pages.&lt;/p&gt;
&lt;p&gt;Per comodità, ecco il codice copiato e incollato dalla pagina dimostrativa.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;DOMContentLoaded&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; bannerContainerId &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;promo-banner&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// ID del contenitore del banner&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; bannerSessionKey &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;promoBannerContent&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; bannerClosedKey &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;promoBannerClosed&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Funzione per verificare se il banner è stato chiuso dall&#39;utente&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;isBannerClosed&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt;
    sessionStorage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getItem&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bannerClosedKey&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Controlla se il banner è stato chiuso in precedenza dall&#39;utente. Se sì, non fare nulla.&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isBannerClosed&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Funzione per iniettare il banner nella pagina&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;injectBanner&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;bannerContent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; bannerContainer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bannerContainerId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bannerContainer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      bannerContainer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;innerHTML &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; bannerContent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      bannerContainer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;block&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// 👀 Controlla se il contenuto del banner esiste in sessionStorage, ed eventualmente iniettalo&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; savedBannerContent &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; sessionStorage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getItem&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bannerSessionKey&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;savedBannerContent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;injectBanner&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;savedBannerContent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Funzione per simulare il recupero della promozione.&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;loadPromotion&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; bannerContent &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;div&gt;Il tuo contenuto promozionale qui&amp;lt;/div&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

      &lt;span class=&quot;token comment&quot;&gt;// Inietta il contenuto del banner&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;injectBanner&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bannerContent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

      &lt;span class=&quot;token comment&quot;&gt;// 👀 Salva il contenuto del banner in sessionStorage per la prossima volta&lt;/span&gt;
      sessionStorage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setItem&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bannerSessionKey&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; bannerContent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;600&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Funzione per gestire l&#39;azione di chiusura del banner&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;closeBanner&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    sessionStorage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setItem&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bannerClosedKey&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; bannerContainer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bannerContainerId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bannerContainer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      bannerContainer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;none&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Simula il recupero della promozione&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;loadPromotion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Esempio di event listener per la chiusura del banner&lt;/span&gt;
  document
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;close-banner&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;click&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; closeBanner&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;script&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;come-funziona&quot; tabindex=&quot;-1&quot;&gt;Come funziona &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/mitigating-cls-caused-by-promotional-banners/#come-funziona&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Session Storage&lt;/strong&gt;: viene utilizzato per memorizzare il contenuto promozionale e lo stato di chiusura del banner. I dati persistono tra i caricamenti di pagina all&#39;interno della stessa sessione, garantendo un&#39;esperienza utente coerente.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Iniezione immediata&lt;/strong&gt;: iniettando immediatamente il contenuto salvato nella pagina, evitiamo qualsiasi spostamento di layout che si verificherebbe se il banner venisse caricato dopo che la pagina è stata completamente renderizzata.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Controllo dell&#39;utente&lt;/strong&gt;: se l&#39;utente chiude il banner, questo non ricomparirà durante la stessa sessione, garantendo il rispetto delle preferenze dell&#39;utente.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/mitigating-cls-caused-by-promotional-banners/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Sfruttando il session storage per gestire la visualizzazione dei banner promozionali, puoi ridurre significativamente il CLS sul tuo sito web. Questo approccio non solo migliora l&#39;esperienza utente, ma ottimizza anche le metriche prestazionali del sito, contribuendo a una migliore SEO e a tassi di coinvolgimento più elevati.&lt;/p&gt;
&lt;p&gt;Questo metodo è particolarmente utile per i siti web con contenuti dinamici, in cui la decisione di mostrare determinati elementi viene presa dopo il caricamento della pagina. Pianificando questi elementi in anticipo, puoi creare un&#39;esperienza più fluida e stabile per i tuoi utenti.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Questo approccio è un modo semplice ma efficace per affrontare una delle cause comuni di CLS, e può essere implementato con modifiche minime al codebase esistente.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Impressioni su Google I/O Connect 2024 + GDE Forum a Berlino</title>
		<link href="https://andreaverlicchi.eu/it/blog/google-io-connect-2024-berlin/"/>
		<updated>2024-08-01T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/google-io-connect-2024-berlin/</id>
		<content type="html">&lt;p&gt;Google I/O è l&#39;evento annuale di Google per sviluppatori che si tiene nei loro uffici in California, negli &lt;abbr title=&quot;Stati Uniti d&#39;America&quot;&gt;USA&lt;/abbr&gt;.
Google I/O Connect è una serie di eventi pratici in presenza per sviluppatori che si tengono in tutto il mondo, per aiutare a mettere in pratica le tecnologie e gli annunci del Google I/O tramite sessioni dal vivo, demo, codelab, office hour e altro ancora.
Come l&#39;anno scorso, sono stato invitato al Google I/O Connect &lt;abbr title=&quot;Europe, Middle-East and Africa&quot;&gt;EMEA&lt;/abbr&gt; 2024.
E in qualità di Google Developer Expert (GDE), il giorno successivo ho partecipato anche al GDE Forum presso gli uffici Google di Berlino.
Continua a leggere per scoprire com&#39;erano questi eventi e cosa mi è piaciuto di più.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/6c6K15oE1u-648.webp 648w, https://andreaverlicchi.eu/img/6c6K15oE1u-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/6c6K15oE1u-648.jpeg 648w, https://andreaverlicchi.eu/img/6c6K15oE1u-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi appoggiato alla barra tra la I e la O del logo di Google I/O Connect ricoperto di fiori&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/6c6K15oE1u-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io, comodamente appoggiato alla barra tra la I e la O del logo di Google I/O Connect&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;la-cena-della-community&quot; tabindex=&quot;-1&quot;&gt;La cena della community &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-io-connect-2024-berlin/#la-cena-della-community&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il giorno prima della conferenza, Google organizza una cena per far incontrare Google Developer Experts (GDE), Women Tech Makers (WTM), organizzatori di Google Developer Groups (GDG) e persone che lavorano in Google (i cosiddetti Googler) nel programma GDE o come developer relationship (devrel).&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/-N-1rdItpM-648.webp 648w, https://andreaverlicchi.eu/img/-N-1rdItpM-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/-N-1rdItpM-648.jpeg 648w, https://andreaverlicchi.eu/img/-N-1rdItpM-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Diversi gruppi di persone che chiacchierano alla cena della community&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/-N-1rdItpM-648.jpeg&quot; width=&quot;1296&quot; height=&quot;984&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Persone che chiacchierano alla cena della community&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;L&#39;obiettivo dell&#39;evento è socializzare, conoscere nuove persone, fare rete con quelle che già si conoscono, rafforzare i legami personali e professionali; il tutto mangiando, bevendo e discutendo delle ultime novità del settore.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Wmyyo4K_PM-648.webp 648w, https://andreaverlicchi.eu/img/Wmyyo4K_PM-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/Wmyyo4K_PM-648.jpeg 648w, https://andreaverlicchi.eu/img/Wmyyo4K_PM-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Google Developer Experts sulle web performance insieme a Barry Pollard, web performance developer advocate&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/Wmyyo4K_PM-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Da sinistra: Ines Akrap, io, Barry Pollard, Fabian Krumbholz, Medhat Dawoud, Jad Joubran, Erwin Hofman, Joan León, Anna Migas.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;L&#39;evento mi è piaciuto molto, ho trascorso la maggior parte del tempo a chiacchierare con altri GDE di web performance e Googler - in particolare Barry Pollard (web performance developer advocate per Google Chrome) e Jocelyn -, ho passato un po&#39; di tempo con la community dei GDG italiani, ho finito per cantare al karaoke con la mia ex collega Ines e, una volta terminato l&#39;evento, ho fatto una lunga passeggiata fino all&#39;hotel con Paolo Galeone, un GDE di Machine Learning che è volato con me da Bologna.&lt;/p&gt;
&lt;h2 id=&quot;l-evento-principale-google-i-o&quot; tabindex=&quot;-1&quot;&gt;L&#39;evento principale Google I/O &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-io-connect-2024-berlin/#l-evento-principale-google-i-o&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il palco principale è stato calcato dai Googler per il keynote iniziale, e io ero lì, seduto in prima fila come piace a me (soprattutto perché sono miope).&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/VRn5JHSgrp-648.webp 648w, https://andreaverlicchi.eu/img/VRn5JHSgrp-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/VRn5JHSgrp-648.jpeg 648w, https://andreaverlicchi.eu/img/VRn5JHSgrp-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Io, Aleksander Denisov e Rowdy Rabouw seduti in prima fila&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/VRn5JHSgrp-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io, Aleksander Denisov e Rowdy Rabouw seduti in prima fila&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Tuttavia, Google I/O Connect NON è una replica del Google I/O, quindi Google richiede di guardare in anticipo i video di ciò che è stato presentato all&#39;evento principale I/O. Poi, a Google I/O Connect, si ha la possibilità di fare domande ai Googler presenti sul palco in merito agli argomenti presentati.&lt;/p&gt;
&lt;p&gt;L&#39;evento è suddiviso in diverse aree tematiche (Web, AI, Android, Flutter, ecc.) in modo da poter seguire quelle di maggiore interesse. Ad esempio, ho trascorso la maggior parte del tempo nell&#39;area Web, seguendo interventi sulle nuove funzionalità della UI web, sull&#39;ultima release di Angular, ecc.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/uCGsIUMD22-648.webp 648w, https://andreaverlicchi.eu/img/uCGsIUMD22-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/uCGsIUMD22-648.jpeg 648w, https://andreaverlicchi.eu/img/uCGsIUMD22-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Una Kravetz, Bramus e Barry Pollard di Google sul palco di The Latest in Web UI&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/uCGsIUMD22-648.jpeg&quot; width=&quot;1296&quot; height=&quot;875&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Una Kravetz, Bramus e Barry Pollard di Google sul palco di The Latest in Web UI&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Lì ho anche avuto la fortuna di incontrare Nishu Goel, che l&#39;anno scorso ha fatto un ottimo lavoro analizzando l&#39;Interaction to Next Paint (INP) e ha tenuto un talk al riguardo alla conferenza Performance Now; per me è una vera rockstar, ma non avevo mai avuto l&#39;opportunità di incontrarla di persona. Quindi, ancora networking.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/FpNsGKx_5s-648.webp 648w, https://andreaverlicchi.eu/img/FpNsGKx_5s-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/FpNsGKx_5s-648.jpeg 648w, https://andreaverlicchi.eu/img/FpNsGKx_5s-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Un selfie con me, Jeremy Wagner, Fabian Krumbholz e Nishu Goel davanti alla strada principale della location di Google I/O Connect&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/FpNsGKx_5s-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Ancora networking! Da sinistra: io, Jeremy Wagner, Fabian Krumbholz e Nishu Goel&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Questo evento era aperto a tutti gli invitati alla cena della community, più altre persone che hanno partecipato acquistando un biglietto.&lt;/p&gt;
&lt;h2 id=&quot;gde-forum&quot; tabindex=&quot;-1&quot;&gt;GDE Forum &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/google-io-connect-2024-berlin/#gde-forum&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il forum GDE era riservato esclusivamente ai Google Developer Experts e aveva un numero di posti limitato (150), per cui vi hanno potuto accedere solo i primi a registrarsi. Io sono stato tra i fortunati, ma conosco molti che sono rimasti in lista d&#39;attesa senza riuscire a entrare.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Phy-CA_SBG-648.webp 648w, https://andreaverlicchi.eu/img/Phy-CA_SBG-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/Phy-CA_SBG-648.jpeg 648w, https://andreaverlicchi.eu/img/Phy-CA_SBG-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Io all&#39;ingresso del GDE Forum di Berlino presso gli uffici di Google, con degli orsetti sopra il logo&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/Phy-CA_SBG-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io all&#39;ingresso del GDE Forum di Berlino presso gli uffici Google&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Qui ho avuto l&#39;opportunità di vedere in anteprima e fornire feedback su alcune delle funzionalità a cui sta lavorando il team di Google Chrome Developer Tools (che non posso rivelare in quanto coperte da &lt;abbr title=&quot;Accordo di riservatezza&quot;&gt;NDA&lt;/abbr&gt;) e di partecipare a una sessione di debug live dell&#39;INP con Barry Pollard (l&#39;evento più apprezzato secondo il sondaggio finale).&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/cW0SWSlvHB-648.webp 648w, https://andreaverlicchi.eu/img/cW0SWSlvHB-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/cW0SWSlvHB-648.jpeg 648w, https://andreaverlicchi.eu/img/cW0SWSlvHB-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Persone sedute davanti allo schermo al keynote iniziale per il GDE Forum&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/cW0SWSlvHB-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Keynote iniziale per il GDE Forum&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;E naturalmente, ancora networking!&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/mSybDR-N6Q-648.webp 648w, https://andreaverlicchi.eu/img/mSybDR-N6Q-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/mSybDR-N6Q-648.jpeg 648w, https://andreaverlicchi.eu/img/mSybDR-N6Q-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Nishu Goel, Barry Pollard e io&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/mSybDR-N6Q-648.jpeg&quot; width=&quot;1296&quot; height=&quot;921&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Ancora networking con Nishu Goel e Barry Pollard&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Per concludere, è stato un evento molto piacevole e utile a cui partecipare, e spero di avere l&#39;opportunità di esserci anche l&#39;anno prossimo.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Il talk di Jake Archibald &quot;In the loop&quot;, trascritto</title>
		<link href="https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/"/>
		<updated>2024-02-17T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/</id>
		<content type="html">&lt;p&gt;Il talk di &lt;a href=&quot;https://jakearchibald.com/&quot;&gt;Jake Archibald&lt;/a&gt; &amp;quot;In the loop&amp;quot; (JS Conf Asia) è ancora una delle migliori fonti di informazioni su come i browser elaborano i task e riescono a rispondere all&#39;input dell&#39;utente. Non avendo trovato nulla di così comprensibile in formato testuale, ho deciso di trascrivere il suo intervento in questo articolo. Trovi il video alla fine.&lt;/p&gt;
&lt;h2 id=&quot;main-thread-e-ordine-deterministico&quot; tabindex=&quot;-1&quot;&gt;Main thread e ordine deterministico &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#main-thread-e-ordine-deterministico&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Prendi i seguenti frammenti di codice:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;el&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
el&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;none&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;el&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;none&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;el&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Diresti che si comportano allo stesso modo per quanto riguarda l&#39;esperienza dell&#39;utente? Gli utenti vedranno un lampeggiamento dovuto all&#39;elemento aggiunto al DOM e subito nascosto?&lt;/p&gt;
&lt;p&gt;La risposta è che i due frammenti di codice si comportano esattamente allo stesso modo, e questo a causa di come funziona il thread principale (main thread).&lt;/p&gt;
&lt;h2 id=&quot;il-thread-principale-main-thread&quot; tabindex=&quot;-1&quot;&gt;Il thread principale (main thread) &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#il-thread-principale-main-thread&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Lo chiamiamo thread principale perché qui accadono un&#39;infinità di cose. È dove viene eseguito JavaScript. È dove avviene il rendering. È dove vive il DOM.&lt;/p&gt;
&lt;p&gt;Ciò significa che le operazioni sul web hanno un ordine deterministico. Non abbiamo diversi frammenti di codice che girano contemporaneamente cercando di modificare lo stesso DOM, il che porterebbe a una sfilza di terribili race condition.&lt;/p&gt;
&lt;p&gt;Ma significa anche che se qualcosa sul thread principale richiede molto tempo (ad esempio 200 millisecondi, che è un&#39;eternità in termini di interazione dell&#39;utente), allora diventa estremamente evidente perché ha bloccato molte altre cose, come il rendering e l&#39;interattività.&lt;/p&gt;
&lt;p&gt;Pensa a un blocco del thread principale come a quando starnutiamo. Tutto il resto si ferma finché lo starnuto non è finito. Inutile dire che non vogliamo scrivere codice che si comporti come uno starnuto.&lt;/p&gt;
&lt;p&gt;Quindi, sebbene ci sia questo thread principale, tendiamo ad avviare tutta una serie di thread collaterali (ad esempio per le richieste di rete, la codifica e decodifica, la crittografia, il monitoraggio dei dispositivi di input), ma una volta che questi thread hanno completato un&#39;operazione di cui la pagina deve essere a conoscenza, devono in qualche modo tornare al thread principale per fornirgli queste informazioni. Ed è proprio l&#39;&lt;strong&gt;event loop&lt;/strong&gt; che orchestra tutto questo.&lt;/p&gt;
&lt;h2 id=&quot;le-code-dei-task-task-queues&quot; tabindex=&quot;-1&quot;&gt;Le code dei task (Task queues) &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#le-code-dei-task-task-queues&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Prendi &lt;code&gt;setTimeout&lt;/code&gt;, ad esempio. Hai mai pensato a come funzioni in realtà? Quando viene invocato, deve eseguire i seguenti passaggi:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;attendere &lt;code&gt;ms&lt;/code&gt; millisecondi&lt;/li&gt;
&lt;li&gt;invocare la callback&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Fatto.&lt;/p&gt;
&lt;p&gt;Eseguiamo questi passaggi in parallelo — il che è un modo per dire che usciamo dal thread principale per eseguire questa roba contemporaneamente ad altro — ma così facendo creiamo un nuovo problema, perché ora stiamo invocando una callback da qualcosa che non è il thread principale, e questo non può funzionare. Finiresti per avere molto codice JavaScript in esecuzione in parallelo che modifica lo stesso DOM, creando inevitabili race condition.&lt;/p&gt;
&lt;p&gt;Quindi facciamo così: accodiamo un task. Accodiamo un task per tornare sul thread principale a un certo punto, e a quel punto eseguiamo JavaScript sul thread in cui vive JavaScript, facendo funzionare tutto correttamente.&lt;/p&gt;
&lt;h2 id=&quot;conosciamo-l-event-loop&quot; tabindex=&quot;-1&quot;&gt;Conosciamo l&#39;event loop &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#conosciamo-l-event-loop&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/xMF_u-B-3e-648.webp 648w, https://andreaverlicchi.eu/img/xMF_u-B-3e-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/xMF_u-B-3e-648.png 648w, https://andreaverlicchi.eu/img/xMF_u-B-3e-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;L&#39;event loop e la deviazione dei task sulla sinistra&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/xMF_u-B-3e-648.png&quot; width=&quot;1296&quot; height=&quot;726&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Questo è come Jake descrive l&#39;event loop. È un cerchio, l&#39;esecuzione gira continuamente finché un task non viene accodato nella &quot;deviazione dei task&quot; a sinistra.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Ora, cosa succede se facciamo questo:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;callback1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;callback2&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ebbene, secondo le specifiche, questi due algoritmi vengono eseguiti in parallelo, ciascuno attende mille millisecondi, e poi devono tornare al thread principale. E lo fanno accodando un task.&lt;/p&gt;
&lt;p&gt;Quindi, il browser dice all&#39;event loop: &amp;quot;Ehi, ho qualcosa qui che vuole eseguire del lavoro sul thread principale. Anzi, ho due cose&amp;quot;, e aggiunge ciascuna di esse come un elemento separato nella coda dei task.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/e2eiThDXOF-648.webp 648w, https://andreaverlicchi.eu/img/e2eiThDXOF-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/e2eiThDXOF-648.png 648w, https://andreaverlicchi.eu/img/e2eiThDXOF-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Due task sono pianificati per l&#39;esecuzione nella coda dei task&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/e2eiThDXOF-648.png&quot; width=&quot;1296&quot; height=&quot;727&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Ora due task sono pianificati per l&#39;esecuzione nella coda dei task&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;L&#39;event loop risponde: &amp;quot;Certo, va bene, me ne occuperò&amp;quot;. Quindi, esegue la prima callback, &lt;strong&gt;fa un giro dell&#39;event loop&lt;/strong&gt; ed esegue la seconda.&lt;/p&gt;
&lt;p&gt;E questi sono i task. Sarebbe piuttosto semplice se fosse tutto qui, ma le cose si complicano quando consideriamo gli step di rendering.&lt;/p&gt;
&lt;h2 id=&quot;gli-step-di-rendering-render-steps&quot; tabindex=&quot;-1&quot;&gt;Gli step di rendering (render steps) &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#gli-step-di-rendering-render-steps&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Questo è ciò che il browser utilizza per aggiornare effettivamente ciò che appare sullo schermo.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/NO5dbNqNiG-648.webp 648w, https://andreaverlicchi.eu/img/NO5dbNqNiG-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/NO5dbNqNiG-648.png 648w, https://andreaverlicchi.eu/img/NO5dbNqNiG-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Gli step di rendering&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/NO5dbNqNiG-648.png&quot; width=&quot;1296&quot; height=&quot;728&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Sul lato destro dell&#39;event loop, gli step di rendering: style, layout, painting&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Gli step di rendering sono un&#39;altra deviazione e coinvolgono il calcolo dello stile.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Style (S): consiste nell&#39;analizzare tutto il CSS presente e calcolare cosa si applica a ciascun elemento.&lt;/li&gt;
&lt;li&gt;Layout (L): consiste nel creare un render tree, calcolando la posizione e le dimensioni di ogni elemento nella pagina.&lt;/li&gt;
&lt;li&gt;Paint (P): consiste nel generare i dati effettivi dei pixel, eseguendo il disegno vero e proprio sulla pagina.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Quindi, a un certo punto il browser dirà all&#39;event loop: &amp;quot;Ehi, sai, dobbiamo aggiornare lo schermo&amp;quot; e l&#39;event loop risponderà: &amp;quot;Nessun problema, me ne occuperò al prossimo giro dell&#39;event loop&amp;quot;.&lt;/p&gt;
&lt;h2 id=&quot;un-ciclo-infinito-con-while-true&quot; tabindex=&quot;-1&quot;&gt;Un ciclo infinito con &lt;code&gt;while(true)&lt;/code&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#un-ciclo-infinito-con-while-true&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ecco una pagina con una GIF, del testo e un grande pulsante che avvia un ciclo infinito in JavaScript.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Kve0XgyRaS-648.webp 648w, https://andreaverlicchi.eu/img/Kve0XgyRaS-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/Kve0XgyRaS-648.png 648w, https://andreaverlicchi.eu/img/Kve0XgyRaS-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Una pagina semplice con la GIF di un gatto, del testo e un pulsante per il ciclo infinito&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/Kve0XgyRaS-648.png&quot; width=&quot;1296&quot; height=&quot;726&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Una pagina semplice con la GIF di un gatto, del testo e un pulsante per il ciclo infinito&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;button&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;click&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;  
    &lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quindi, se clicco quel pulsante, tutto si ferma. La GIF si blocca. Non posso più selezionare il testo. L&#39;intera scheda va in stallo.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/IWfBvsvjEf-648.webp 648w, https://andreaverlicchi.eu/img/IWfBvsvjEf-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/IWfBvsvjEf-648.png 648w, https://andreaverlicchi.eu/img/IWfBvsvjEf-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Il punto di esecuzione è bloccato nel singolo task in coda&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/IWfBvsvjEf-648.png&quot; width=&quot;1296&quot; height=&quot;728&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Visualizzazione dell&#39;event loop che esegue un ciclo infinito&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;L&#39;utente clicca sul pulsante, quindi il browser dice: &amp;quot;Ehi, event loop, ho un task per te&amp;quot;, e l&#39;event loop risponde: &amp;quot;Sì, nessun problema, me ne occupo io&amp;quot;. Ma questo task non finisce mai. Continua a eseguire JavaScript all&#39;infinito.&lt;/p&gt;
&lt;p&gt;Un paio di millisecondi dopo il browser dice: &amp;quot;Ehi, event loop, dobbiamo aggiornare la GIF sulla pagina. Quindi, se potessi effettuare il rendering non appena sei libero, sarebbe fantastico&amp;quot;. L&#39;event loop risponde: &amp;quot;Sì, okay, me ne occuperò subito dopo aver finito questo ciclo infinito in cui sono impegnato in questo momento&amp;quot;.&lt;/p&gt;
&lt;p&gt;Poi l&#39;utente prova a evidenziare del testo, il che comporta operazioni come l&#39;hit testing ed esaminare il DOM per capire quale sia il testo effettivo. Quindi, il browser dice: &amp;quot;Ehi, ho altri elementi da aggiungere alla tua lista di cose da fare&amp;quot;. E l&#39;event loop risponde: &amp;quot;Stai scherzando? Hai idea di quanto tempo ci voglia per completare un ciclo infinito? È un sacco di tempo. C&#39;è un indizio nel nome stesso&amp;quot;.&lt;/p&gt;
&lt;p&gt;Ecco perché un ciclo &lt;code&gt;while&lt;/code&gt; blocca il rendering e le altre interazioni della pagina. Ma nella pratica questo è un bene. Diamo di nuovo un&#39;occhiata al codice iniziale.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;el&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
el&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;none&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Un tempo mi preoccupavo che questo potesse causare un lampeggiamento dei contenuti (flash of content), ma non è possibile, giusto? Perché questo script viene eseguito come parte di un task, il quale deve essere completato del tutto prima che il browser possa tornare a occuparsi degli step di rendering.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;L&#39;event loop garantisce che il tuo task sarà completato prima che avvenga il rendering successivo.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;un-ciclo-infinito-con-settimeout&quot; tabindex=&quot;-1&quot;&gt;Un ciclo infinito con &lt;code&gt;setTimeout()&lt;/code&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#un-ciclo-infinito-con-settimeout&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Questo è un ciclo, ma ogni volta che lo eseguiamo usiamo &lt;code&gt;setTimeout&lt;/code&gt; per accodare la chiamata successiva.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;loop&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Se eseguiamo questo ciclo &lt;code&gt;setTimeout&lt;/code&gt; nella pagina demo, sembra che non sia cambiato nulla, ma ecco cosa succede dietro le quinte.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/1gyYELhudJ-648.webp 648w, https://andreaverlicchi.eu/img/1gyYELhudJ-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/1gyYELhudJ-648.png 648w, https://andreaverlicchi.eu/img/1gyYELhudJ-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Il punto di esecuzione si sposta verso il task successivo in coda&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/1gyYELhudJ-648.png&quot; width=&quot;1296&quot; height=&quot;725&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;L&#39;esecuzione di un ciclo &lt;code&gt;setTimeout&lt;/code&gt; esegue un singolo task, per poi accodarne un altro&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Accodiamo un task, facciamo un giro dell&#39;event loop, prendiamo quel task e, di conseguenza, ne accodiamo un altro.&lt;/p&gt;
&lt;p&gt;Questo continua a succedere all&#39;infinito, ma come abbiamo già visto, può essere elaborato solo un task alla volta. Quindi, quando elabora un task, l&#39;event loop deve fare un intero giro completo per raccogliere il task successivo.&lt;/p&gt;
&lt;p&gt;Ciò significa che a un certo punto il browser può dire: &amp;quot;Uhm, dovremmo aggiornare la visualizzazione di quella GIF&amp;quot;, perché in quel momento ha la possibilità di deviare e aggiornare lo schermo.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/wZDtA2dI97-648.webp 648w, https://andreaverlicchi.eu/img/wZDtA2dI97-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/wZDtA2dI97-648.png 648w, https://andreaverlicchi.eu/img/wZDtA2dI97-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Il punto di esecuzione si sposta verso gli step di rendering&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/wZDtA2dI97-648.png&quot; width=&quot;1296&quot; height=&quot;727&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Dopo l&#39;esecuzione di quella callback di &lt;code&gt;setTimeout&lt;/code&gt;, il ciclo è in grado di effettuare il rendering&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Ed è per questo che un ciclo &lt;code&gt;setTimeout&lt;/code&gt; non blocca il rendering.&lt;/p&gt;
&lt;h2 id=&quot;requestanimationframe&quot; tabindex=&quot;-1&quot;&gt;&lt;code&gt;requestAnimationFrame&lt;/code&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#requestanimationframe&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ora, se vuoi eseguire del codice che ha a che fare con il rendering, un task è davvero il posto sbagliato per farlo, perché un task si trova all&#39;estremo opposto rispetto a tutto ciò che riguarda il rendering, per quanto concerne l&#39;event loop. Quello che vogliamo fare è eseguire il codice negli step di rendering.&lt;/p&gt;
&lt;p&gt;Vogliamo eseguire il codice qui:&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/W_NRlUdy82-648.webp 648w, https://andreaverlicchi.eu/img/W_NRlUdy82-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/W_NRlUdy82-648.png 648w, https://andreaverlicchi.eu/img/W_NRlUdy82-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Un riquadro giallo contrassegnato con rAF è apparso prima del blocco style nella deviazione del rendering&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/W_NRlUdy82-648.png&quot; width=&quot;1296&quot; height=&quot;727&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;&lt;code&gt;requestAnimationFrame&lt;/code&gt; è il riquadro giallo etichettato come &quot;rAF&quot; che appare prima del blocco di calcolo dello stile (S) nella deviazione del rendering&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;E il browser ci permette di farlo utilizzando &lt;code&gt;requestAnimationFrame&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Le callback &amp;quot;rAF&amp;quot; vengono eseguite come parte degli step di rendering. Per mostrare perché questo sia utile, animerò una scatola, una semplice scatola, usando questo codice.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/fyHs2P66sI-648.webp 648w, https://andreaverlicchi.eu/img/fyHs2P66sI-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/fyHs2P66sI-648.png 648w, https://andreaverlicchi.eu/img/fyHs2P66sI-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Un riquadro quadrato su sfondo blu&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/fyHs2P66sI-648.png&quot; width=&quot;1296&quot; height=&quot;726&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Il riquadro che sta per essere animato&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;moveBoxForwardOnePixel&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;requestAnimationFrame&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;callback&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quindi sposterò il riquadro in avanti di un pixel, e poi userò &lt;code&gt;requestAnimationFrame&lt;/code&gt; per creare un ciclo. Tutto qui. Non fa nient&#39;altro.&lt;/p&gt;
&lt;p&gt;Ma cosa succederebbe se sostituissimo &lt;code&gt;requestAnimationFrame&lt;/code&gt; con &lt;code&gt;setTimeout&lt;/code&gt;?&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;moveBoxForwardOnePixel&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;callback&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Il risultato è questo:&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/HQUe1Cnk27-648.webp 648w, https://andreaverlicchi.eu/img/HQUe1Cnk27-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/HQUe1Cnk27-648.png 648w, https://andreaverlicchi.eu/img/HQUe1Cnk27-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Due riquadri quadrati su sfondo blu, il primo etichettato requestAnimationFrame, il secondo setTimeout&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/HQUe1Cnk27-648.png&quot; width=&quot;1296&quot; height=&quot;726&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;I due riquadri mentre vengono animati. Quello con &lt;code&gt;setTimeout&lt;/code&gt; si muove più velocemente di quello con &lt;code&gt;requestAnimationFrame&lt;/code&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Il nuovo riquadro animato con &lt;code&gt;setTimeout&lt;/code&gt; si muove circa 3,5 volte più velocemente, il che significa che questa callback viene chiamata più spesso, e questo non è affatto un bene.&lt;/p&gt;
&lt;p&gt;Abbiamo visto in precedenza che il rendering può avvenire tra un task e l&#39;altro. Ma solo perché può avvenire, non significa che debba per forza succedere.&lt;/p&gt;
&lt;p&gt;Possiamo eseguire un task, chiederci &amp;quot;Dobbiamo fare il rendering?&amp;quot; e la risposta potrebbe essere &amp;quot;No, non ne vale ancora la pena&amp;quot;.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Q08beXeA_D-648.webp 648w, https://andreaverlicchi.eu/img/Q08beXeA_D-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/Q08beXeA_D-648.png 648w, https://andreaverlicchi.eu/img/Q08beXeA_D-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Nell&#39;event loop, l&#39;interruttore che porta alla deviazione del rendering è chiuso&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/Q08beXeA_D-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Dobbiamo renderizzare? Non ancora.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Facciamo un giro dell&#39;event loop, prendiamo un altro task. &amp;quot;Renderizziamo adesso?&amp;quot;, &amp;quot;No, non sembra il momento giusto&amp;quot;. Possono verificarsi molti task prima che il browser decida: &amp;quot;Sì, in realtà al prossimo giro aggiorneremo lo schermo&amp;quot;.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/xFlMrtzs9O-648.webp 648w, https://andreaverlicchi.eu/img/xFlMrtzs9O-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/xFlMrtzs9O-648.png 648w, https://andreaverlicchi.eu/img/xFlMrtzs9O-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Nell&#39;event loop, l&#39;interruttore che porta alla deviazione del rendering è aperto&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/xFlMrtzs9O-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Dobbiamo renderizzare? Ora è il momento.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Il browser decide quando fare questo e cerca di essere il più efficiente possibile. Gli step di rendering avvengono solo se c&#39;è effettivamente qualcosa da aggiornare. Se non è cambiato nulla, non si disturberà.&lt;/p&gt;
&lt;p&gt;Ad esempio, se la scheda del browser è in background e non è visibile, non eseguirà mai gli step di rendering perché non avrebbe senso. Inoltre, la maggior parte degli schermi si aggiorna a una frequenza fissa. Nella maggior parte dei casi si tratta di 60 volte al secondo. Alcuni schermi sono più veloci, altri più lenti, ma i 60 Hz rappresentano lo standard più comune.&lt;/p&gt;
&lt;p&gt;Quindi, se modificassimo gli stili della pagina mille volte al secondo, il browser non eseguirebbe gli step di rendering mille volte al secondo: si sincronizzerà con lo schermo e renderizzerà solo fino alla frequenza massima supportata dal display. Solitamente, 60 volte al secondo.&lt;/p&gt;
&lt;p&gt;Altrimenti sarebbe solo una perdita di tempo; non ha senso renderizzare elementi che l&#39;utente non vedrà mai. Ma è proprio quello che fa &lt;code&gt;setTimeout&lt;/code&gt; in questo caso. Si muove più velocemente perché aggiorna la posizione del riquadro più volte di quante l&#39;utente possa effettivamente vederlo, più volte rispetto a quanto il display sia in grado di mostrare.&lt;/p&gt;
&lt;h4 id=&quot;altri-modi-per-accodare-un-task&quot; tabindex=&quot;-1&quot;&gt;Altri modi per accodare un task &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#altri-modi-per-accodare-un-task&quot;&gt;#&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Finora abbiamo usato &lt;code&gt;setTimeout&lt;/code&gt; come scorciatoia per dire &amp;quot;accodare un task&amp;quot;, ma in realtà non lo è. Anche se impostiamo 0 millisecondi per la callback, il browser utilizzerà di default circa 4,7 millisecondi (le specifiche dicono che il browser può scegliere qualsiasi numero, ma Jake ha effettuato test e misurazioni precise).&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/eqUCIZRie3-648.webp 648w, https://andreaverlicchi.eu/img/eqUCIZRie3-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/eqUCIZRie3-648.png 648w, https://andreaverlicchi.eu/img/eqUCIZRie3-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Tre riquadri quadrati su sfondo blu, il primo etichettato requestAnimationFrame, il secondo setTimeout, il terzo queueTask&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/eqUCIZRie3-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;I tre riquadri mentre vengono animati. Quello etichettato come &lt;code&gt;queueTask&lt;/code&gt; si muove così velocemente da apparire in posizioni casuali sulla sua riga&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Non esiste un singolo metodo che si limiti ad accodare un task, ma possiamo simularlo usando i MessageChannel. Jake ha fatto un test proprio con questo approccio.&lt;/p&gt;
&lt;p&gt;Il risultato è che si verificano così tanti task che il riquadro sembra assumere posizioni casuali. Riceviamo un task ogni due centesimi (2/100) di millisecondo. Quindi il rendering può avvenire tra i task, ma si possono avere molti task, persino decine di migliaia, tra un rendering e l&#39;altro.&lt;/p&gt;
&lt;h2 id=&quot;task-e-frame-nel-tempo&quot; tabindex=&quot;-1&quot;&gt;Task e frame nel tempo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#task-e-frame-nel-tempo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Immaginiamo che ciascuno di questi sia un frame mostrato all&#39;utente.&lt;/p&gt;
&lt;p&gt;Quindi, i nostri step di rendering avvengono all&#39;inizio di ciascun frame e questo include il calcolo dello stile, il layout e il paint, anche se non necessariamente tutti e tre ogni volta.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/sUqQCbVCDl-648.webp 648w, https://andreaverlicchi.eu/img/sUqQCbVCDl-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/sUqQCbVCDl-648.png 648w, https://andreaverlicchi.eu/img/sUqQCbVCDl-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Tre rettangoli che rappresentano i frame, ciascuno contenente un rettangolo viola e uno verde che rappresentano le attività di stile e rendering&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/sUqQCbVCDl-648.png&quot; width=&quot;1296&quot; height=&quot;727&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Tre frame, ciascuno contenente un task di stile (viola) e uno di rendering (verde)&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Dipende da cosa deve effettivamente essere aggiornato, ma questo mi piace. È molto ordinato e pulito. È una bellissima rappresentazione.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/evBQx4KYmZ-648.webp 648w, https://andreaverlicchi.eu/img/evBQx4KYmZ-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/evBQx4KYmZ-648.png 648w, https://andreaverlicchi.eu/img/evBQx4KYmZ-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;I task vengono eseguiti ovunque durante un singolo frame&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/evBQx4KYmZ-648.png&quot; width=&quot;1296&quot; height=&quot;728&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;I task vengono eseguiti ovunque durante un singolo frame&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I task, d&#39;altro canto, non si curano affatto del frame. Appaiono semplicemente dove capita. L&#39;event loop garantisce che avvengano nel giusto ordine, ovvero l&#39;ordine in cui sono stati accodati, ma in termini di tempistiche all&#39;interno di un singolo frame non vi è alcun tipo di sincronizzazione.&lt;/p&gt;
&lt;p&gt;E lo abbiamo visto con il nostro &lt;code&gt;setTimeout&lt;/code&gt;. Ne ricevevamo tre o quattro per frame, il che significa che tre quarti di quelle callback erano sforzi inutili in termini di rendering.&lt;/p&gt;
&lt;figure&gt;
	 &lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/F-dI3j6qJM-648.webp 648w, https://andreaverlicchi.eu/img/F-dI3j6qJM-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/F-dI3j6qJM-648.png 648w, https://andreaverlicchi.eu/img/F-dI3j6qJM-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Stessa figura precedente, ora 3 rettangoli gialli su 4 sono spostati, a rappresentare lo sforzo sprecato&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/F-dI3j6qJM-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;3 task su 4 evidenziati come sforzo sprecato in termini di rendering&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Le vecchie librerie di animazione facevano qualcosa del genere, cercando di usare un valore in millisecondi che desse loro circa 60 callback al secondo...&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;animFrame&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;...e assumevano molto sullo schermo. Si dava per scontato che lo schermo fosse a 60 Hz, che all&#39;epoca era il caso comune.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/s6MJKzYi7J-648.webp 648w, https://andreaverlicchi.eu/img/s6MJKzYi7J-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/s6MJKzYi7J-648.png 648w, https://andreaverlicchi.eu/img/s6MJKzYi7J-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;I task vengono pianificati in ogni frame usando setTimeout&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/s6MJKzYi7J-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;I task vengono pianificati in ogni frame usando &lt;code&gt;setTimeout&lt;/code&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Funzionava in qualche modo, eliminando parte del lavoro duplicato. Purtroppo si trattava di un enorme hack, perché setTimeout non è stato progettato per le animazioni e questo si nota: a causa di imprecisioni temporali si finisce per avere delle discrepanze (drift).&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/5GXsZPZ9_I-648.webp 648w, https://andreaverlicchi.eu/img/5GXsZPZ9_I-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/5GXsZPZ9_I-648.png 648w, https://andreaverlicchi.eu/img/5GXsZPZ9_I-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Un quadrato giallo che doveva trovarsi nel secondo frame appare nel terzo frame&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/5GXsZPZ9_I-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Un task doveva essere eseguito nel secondo frame, ma è stato eseguito nel terzo frame&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Quello che succede qui è che non facciamo nulla in un frame e poi nel frame successivo facciamo il doppio del lavoro; questo provoca un&#39;interruzione visiva (visual jank) per l&#39;utente, e non è bello da vedere.&lt;/p&gt;
&lt;p&gt;Inoltre, si blocca uno dei tuoi task per molto tempo, puoi finire per spostare gli step di rendering perché tutto gira sullo stesso thread, andando a disturbare quella precisa routine del browser.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/eEXu-sJktg-648.webp 648w, https://andreaverlicchi.eu/img/eEXu-sJktg-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/eEXu-sJktg-648.png 648w, https://andreaverlicchi.eu/img/eEXu-sJktg-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Quadrati gialli che partono all&#39;interno di ciascun frame, il primo dei quali si estende nel frame successivo&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/eEXu-sJktg-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;I frame partono all&#39;interno di ciascun blocco, e il primo di essi viene eseguito a cavallo del frame successivo&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Se usiamo &lt;code&gt;requestAnimationFrame&lt;/code&gt; anziché &lt;code&gt;setTimeout&lt;/code&gt;, la situazione apparirà molto più simile a questa. Tutto pulito e ordinato. Tutto in fila. Ogni cosa rientra nelle tempistiche del frame, persino questo task più lungo.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/rH1aw-ePOj-648.webp 648w, https://andreaverlicchi.eu/img/rH1aw-ePOj-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/rH1aw-ePOj-648.png 648w, https://andreaverlicchi.eu/img/rH1aw-ePOj-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;I rettangoli gialli che rappresentano i task sono raggruppati all&#39;inizio di ciascun frame&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/rH1aw-ePOj-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;I task sono raggruppati all&#39;inizio di ogni frame, utilizzando &lt;code&gt;requestAnimationFrame&lt;/code&gt; invece di &lt;code&gt;setTimeout&lt;/code&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Jake afferma che quando vede tracce di performance come queste si sente felice, perché mostrano una buona esperienza utente.&lt;/p&gt;
&lt;p&gt;Ovviamente non si possono evitare completamente i task, perché elementi come gli eventi click ti verranno recapitati tramite un task, e in genere si desidera rispondere ad essi il prima possibile. Ma se hai timer o dati provenienti dalla rete, Jake consiglia di usare &lt;code&gt;requestAnimationFrame&lt;/code&gt; per raggruppare quel lavoro, specialmente se hai già delle animazioni in corso, in modo da risparmiarti un sacco di lavoro duplicato.&lt;/p&gt;
&lt;h2 id=&quot;task-e-tempistiche-di-rendering&quot; tabindex=&quot;-1&quot;&gt;Task e tempistiche di rendering &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#task-e-tempistiche-di-rendering&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;C&#39;è un ultimo dettaglio su cui voglio soffermarmi, ed è qualcosa che trae in inganno molti sviluppatori (ha ingannato anche me). &lt;code&gt;requestAnimationFrame&lt;/code&gt; viene eseguito prima dell&#39;elaborazione del CSS e prima del paint.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;button&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;click&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	box&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;none&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	box&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;block&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	box&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;none&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	box&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;block&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	box&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;none&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	box&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;block&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	box&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;none&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	box&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;block&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	box&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;none&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quindi, un codice come questo potrebbe sembrare costoso, dato che stiamo mostrando e nascondendo un elemento molte volte, ma in realtà è molto economico, poiché JavaScript completerà sempre la sua esecuzione prima che avvenga il rendering.&lt;/p&gt;
&lt;p&gt;Quindi, mentre fai questo, il browser si rilassa, ti lascia divertire a cambiare i valori e non pensa minimamente al CSS. Alla fine, quando arriva il momento di eseguire gli step di rendering, analizza la situazione e si chiede: &amp;quot;Ok, cosa hai effettivamente cambiato alla fine?&amp;quot; E l&#39;unica parte che conta davvero è l&#39;ultima riga.&lt;/p&gt;
&lt;p&gt;So il codice sopra, in termini di rendering, equivale al seguente frammento:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;button&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;click&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	box&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;none&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;animare-un-elemento&quot; tabindex=&quot;-1&quot;&gt;Animare un elemento? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#animare-un-elemento&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Sto omettendo la parte in cui Jake spiega come accodare del codice JavaScript per animare un elemento da 1000 a 500 pixel utilizzando una doppia callback &lt;code&gt;requestAnimationFrame&lt;/code&gt;, poiché non è più rilevante al momento della scrittura: le &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API&quot;&gt;Web Animation API&lt;/a&gt;, che all&#39;epoca del talk di Jake erano disponibili solo su Chrome, sono ormai supportate da tutti i browser.&lt;/p&gt;
&lt;h2 id=&quot;microtask&quot; tabindex=&quot;-1&quot;&gt;Microtask &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#microtask&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Negli anni &#39;90, i browser volevano fornire agli sviluppatori un modo per monitorare le modifiche al DOM e il W3C creò i mutation event.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;DOMNodeInserted&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Stuff added to the &amp;lt;body&gt;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In questo modo potevo dire, ad esempio, che volevo sapere quando un nodo veniva inserito all&#39;interno dell&#39;elemento &lt;code&gt;body&lt;/code&gt;. E si riceveva anche una serie di altri eventi correlati.&lt;/p&gt;
&lt;p&gt;Ma nella pratica questo approccio si è rivelato alquanto problematico.&lt;/p&gt;
&lt;p&gt;Prendiamo questo pezzo di codice: sto inserendo cento elementi &lt;code&gt;span&lt;/code&gt; all&#39;interno dell&#39;elemento &lt;code&gt;body&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; span &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;span&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;span&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	span&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;textContent &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Hello&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quanti eventi ti aspetteresti di ricevere come risultato?
Un solo evento? Un evento unico per l&#39;intera operazione? No.
100 eventi? Uno per ogni span. Sì.&lt;/p&gt;
&lt;p&gt;Ma anche un altro centinaio per &lt;code&gt;span.textContent = &#39;Hello&#39;;&lt;/code&gt; quando il nodo di testo entra nello span. E poiché questi eventi si propagano (bubble), questo semplice frammento di codice finirà per generare ben 200 eventi.&lt;/p&gt;
&lt;p&gt;A causa di ciò, modifiche del DOM relativamente semplici finivano per scatenare migliaia di eventi, e se eseguivi anche solo un minimo lavoro all&#39;interno di questi listener, questo si accumulava rapidamente diventando un disastro in termini di prestazioni.&lt;/p&gt;
&lt;p&gt;Quello che volevamo davvero era un modo per ricevere notifiche su un blocco (batch) di queste operazioni, in modo simile a quanto visto prima per gli stili.
Vogliamo che il browser si rilassi, ci lasci fare le nostre operazioni e poi, in un momento opportuno, ci segnali che qualcosa è cambiato.
Qualcosa che rappresenti cumulativamente tutti questi cambiamenti.&lt;/p&gt;
&lt;p&gt;Vogliamo ricevere la notifica una sola volta, non 200 volte. E la soluzione sono stati i mutation observer. Che hanno introdotto una nuova coda chiamata microtask.&lt;/p&gt;
&lt;p&gt;Molta documentazione che ho letto sui microtask suggerisce che vengano eseguiti a ogni giro dell&#39;event loop o dopo un task o qualcosa del genere, ed è in parte vero. C&#39;è un punto specifico dell&#39;event loop in cui i microtask vengono elaborati, ma in genere non è lì che li incontrerai. Essi vengono eseguiti anche ogni volta che JavaScript termina l&#39;esecuzione di uno script.&lt;/p&gt;
&lt;p&gt;Ciò significa che lo stack di JavaScript si svuota completamente, ed è proprio in quel momento che eseguiamo i microtask.&lt;/p&gt;
&lt;p&gt;Quindi puoi trovarti con microtask eseguiti a metà di un task, o all&#39;interno degli step di rendering come parte di &lt;code&gt;requestAnimationFrame&lt;/code&gt;, praticamente ovunque possa essere eseguito JavaScript.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; span &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;span&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;span&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	span&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;textContent &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Hello&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ciò significa che questo JavaScript verrà eseguito fino alla fine, aggiungendo i cento span e i relativi contenuti. JavaScript termina l&#39;esecuzione e viene attivata la callback del nostro mutation observer.&lt;/p&gt;
&lt;p&gt;Anche le Promise fanno uso dei microtask.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;Promise&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;resolve&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Hey!&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Yo!&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quindi, qui accodiamo un microtask e poi stampiamo &#39;Yo!&#39;. JavaScript ha terminato l&#39;esecuzione. Quindi, passiamo ai microtask e stampiamo &#39;Hey!&#39;.&lt;/p&gt;
&lt;p&gt;Questo significa che quando la callback della Promise viene eseguita, hai la garanzia che nessun altro codice JavaScript si trovi a metà esecuzione in quel momento, poiché la callback della Promise è proprio alla base dello stack, ed è per questo che le Promise utilizzano i microtask.&lt;/p&gt;
&lt;h2 id=&quot;un-ciclo-infinito-con-promise-resolve&quot; tabindex=&quot;-1&quot;&gt;Un ciclo infinito con &lt;code&gt;Promise.resolve()&lt;/code&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#un-ciclo-infinito-con-promise-resolve&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ma cosa succede se creiamo un ciclo utilizzando i microtask? In termini di codice, in modo simile a quanto fatto in precedenza con &lt;code&gt;setTimeout&lt;/code&gt; &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#un-ciclo-infinito-con-settimeout&quot;&gt;in precedenza&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	Promise&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;resolve&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;loop&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/mUeG6U3eES-648.webp 648w, https://andreaverlicchi.eu/img/mUeG6U3eES-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/mUeG6U3eES-648.png 648w, https://andreaverlicchi.eu/img/mUeG6U3eES-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Una pagina web con la GIF di un gatto, del testo e un pulsante etichettato &amp;quot;Microtask Loop&amp;quot;&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/mUeG6U3eES-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Di nuovo la stessa demo: la GIF di un gatto, del testo e un pulsante con scritto &quot;Microtask Loop&quot;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Cliccando sul pulsante... il rendering si blocca e la scheda va in stallo esattamente come succedeva con il ciclo &lt;code&gt;while&lt;/code&gt;, in modo del tutto diverso rispetto al &lt;code&gt;setTimeout&lt;/code&gt; visto prima.&lt;/p&gt;
&lt;p&gt;Quindi, le callback delle &lt;code&gt;Promise&lt;/code&gt; sono asincrone, d&#39;accordo, ma cosa significa in realtà asincrono?
Significa semplicemente che avvengono dopo l&#39;esecuzione del codice sincrono, ed è per questo che viene stampato &#39;Yo!&#39; prima di &#39;Hey!&#39;.
Ma il semplice fatto di essere asincrono non significa che debba cedere il controllo al rendering, né che debba cedere il passo a una parte specifica dell&#39;event loop.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/mmhyo-LkSN-648.webp 648w, https://andreaverlicchi.eu/img/mmhyo-LkSN-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/mmhyo-LkSN-648.png 648w, https://andreaverlicchi.eu/img/mmhyo-LkSN-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Tre pile di rettangoli contenenti ciascuno la parola &amp;quot;Item&amp;quot;. La prima pila è etichettata Tasks, la seconda &amp;quot;Animation callbacks&amp;quot;, la terza &amp;quot;Microtasks&amp;quot;&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/mmhyo-LkSN-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Tre tipi di code: Tasks, Animation Callbacks, Microtasks&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Finora abbiamo esaminato tre diverse code. Abbiamo visto la coda dei task, la coda delle callback di animazione (in cui avvengono le callback di &lt;code&gt;requestAnimationFrame&lt;/code&gt;) e ora stiamo guardando i microtask. E, giusto per semplificarci la vita, ognuna di esse viene elaborata in modo leggermente diverso.&lt;/p&gt;
&lt;p&gt;Come abbiamo visto con la coda dei task, preleviamo un solo elemento alla volta. E se viene accodato un altro elemento, questo va semplicemente alla fine della coda. E fin qui tutto bene.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/S5ndBRP0OV-648.webp 648w, https://andreaverlicchi.eu/img/S5ndBRP0OV-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/S5ndBRP0OV-648.png 648w, https://andreaverlicchi.eu/img/S5ndBRP0OV-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;La stessa immagine mostrata nella figura precedente, ma ora il primo elemento in cima alla coda dei task è verde ed è etichettato &amp;quot;Additional item&amp;quot;&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/S5ndBRP0OV-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;L&#39;elemento aggiuntivo aggiunto alla coda dei task non viene elaborato immediatamente&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Le callback di animazione vengono eseguite fino al completamento, ad eccezione di quelle accodate durante l&#39;elaborazione delle callback stesse, le quali vengono rimandate al frame successivo.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/pZ9jzhbQJH-648.webp 648w, https://andreaverlicchi.eu/img/pZ9jzhbQJH-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/pZ9jzhbQJH-648.png 648w, https://andreaverlicchi.eu/img/pZ9jzhbQJH-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;La stessa immagine mostrata nella figura precedente, ma ora tutti gli elementi nella coda requestAnimationFrame sono verdi ed etichettati &amp;quot;Additional item&amp;quot;&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/pZ9jzhbQJH-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Tutti i task della coda &lt;code&gt;requestAnimationFrame&lt;/code&gt; vengono elaborati, tranne quelli appena aggiunti&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I microtask, d&#39;altro canto, vengono elaborati fino al completo svuotamento della coda, inclusi tutti gli elementi che vengono accodati durante l&#39;elaborazione stessa.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/QBKz5LWGEF-648.webp 648w, https://andreaverlicchi.eu/img/QBKz5LWGEF-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/QBKz5LWGEF-648.png 648w, https://andreaverlicchi.eu/img/QBKz5LWGEF-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;La stessa immagine mostrata nella figura precedente, ma ora tutti gli elementi nella coda dei microtask sono verdi, etichettati &amp;quot;Additional item&amp;quot;, e altri appaiono in cima&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/QBKz5LWGEF-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;I nuovi microtask continuano ad essere elaborati fino a quando la coda non è vuota&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Quindi, se aggiungi elementi alla coda alla stessa velocità con cui li elabori, continuerai a elaborare microtask all&#39;infinito.
L&#39;event loop non può proseguire finché quella coda non si è svuotata del tutto. Ed è per questo che il rendering si blocca.&lt;/p&gt;
&lt;h2 id=&quot;altro-nel-video&quot; tabindex=&quot;-1&quot;&gt;Altro nel video &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#altro-nel-video&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il talk termina con alcuni quiz JavaScript sui microtask e sull&#39;ordine di esecuzione, ma questo articolo è già lunghiiiiiissimo, quindi se vuoi davvero risolvere i quesiti ti consiglio di guardare il video.&lt;/p&gt;
&lt;p&gt;Dovresti davvero guardare il video originale se non l&#39;hai ancora fatto, perché le &amp;quot;slide&amp;quot; create da Jake utilizzano animazioni straordinarie che spiegano tutto in modo perfetto.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/cCOL7MC4Pl0?si=EEhZlFn4UuzsfCpj&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen=&quot;&quot; loading=&quot;lazy&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/jake-archibald-in-the-loop-jsconf-asia-talk-transposed/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Spero che tu abbia trovato utile questa trascrizione del talk di Jake!
Mi ha davvero aiutato a capire come funzionano i browser sotto il cofano.&lt;/p&gt;
&lt;p&gt;Mi ci è voluto un po&#39; per scriverlo, se ti va offrimi un caffè su &lt;a href=&quot;https://ko-fi.com/verlok&quot;&gt;Kofi&lt;/a&gt;.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Snippet di web performance per il debug dell&#39;INP in Chrome DevTools</title>
		<link href="https://andreaverlicchi.eu/it/blog/web-performance-snippets-debug-inp-lcp-cls-core-web-vitals-in-chrome-dev-tools/"/>
		<updated>2024-02-14T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/web-performance-snippets-debug-inp-lcp-cls-core-web-vitals-in-chrome-dev-tools/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Ae26uAWD0H-648.webp 648w, https://andreaverlicchi.eu/img/Ae26uAWD0H-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/Ae26uAWD0H-648.png 648w, https://andreaverlicchi.eu/img/Ae26uAWD0H-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Uno screenshot di un&#39;interazione nella scheda performance trace&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/Ae26uAWD0H-648.png&quot; width=&quot;1296&quot; height=&quot;526&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Uno screenshot del debug di un&#39;interazione nella performance trace. Crediti: web.dev&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Dopo averli tenuti sul mio computer per alcuni giorni, ho deciso di pubblicare su GitHub questa raccolta di snippet di web performance per fare il debug dell&#39;INP in Chrome Developer Tools, o per inviare i dati ai tuoi sistemi di analytics.&lt;/p&gt;
&lt;p&gt;👉 &lt;strong&gt;&lt;a href=&quot;https://github.com/verlok/webperf-snippets&quot;&gt;Trovali qui&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Buon debug delle web performance!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Come usare scheduler.yield per migliorare la reattività delle pagine web</title>
		<link href="https://andreaverlicchi.eu/it/blog/how-to-use-scheduler-yield-to-improve-web-page-responsiveness/"/>
		<updated>2023-08-31T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/how-to-use-scheduler-yield-to-improve-web-page-responsiveness/</id>
		<content type="html">&lt;figure&gt;
	&lt;img alt=&quot;Un segnale stradale, un triangolo bianco con bordo rosso con all&#39;interno la parola YIELD in rosso&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/0ZQEV3SwTA-648.webp&quot; width=&quot;1296&quot; height=&quot;864&quot; srcset=&quot;https://andreaverlicchi.eu/img/0ZQEV3SwTA-648.webp 648w, https://andreaverlicchi.eu/img/0ZQEV3SwTA-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;
	&lt;figcaption&gt;Un&#39;immagine casuale per rappresentare il dare la precedenza (yield)&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Nell&#39;agosto del 2023, Google ha introdotto &lt;code&gt;scheduler.yield&lt;/code&gt;, disponibile come origin trial in Chrome 115 e versioni successive.&lt;/p&gt;
&lt;h2 id=&quot;cos-e&quot; tabindex=&quot;-1&quot;&gt;Cos&#39;è &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-use-scheduler-yield-to-improve-web-page-responsiveness/#cos-e&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;scheduler.yield&lt;/code&gt; è una nuova funzionalità di Chrome che consente agli sviluppatori web di cedere esplicitamente il controllo (yield) al thread principale. Ciò può essere utile per attività che richiedono molto tempo, in quanto consente ad &lt;em&gt;altri&lt;/em&gt; task di ottenere tempo di esecuzione sul thread principale prima (rispetto a dover attendere il completamento di task molto lunghi).&lt;/p&gt;
&lt;p&gt;Quando cedi esplicitamente il controllo, stai dicendo al browser: &amp;quot;Ehi, capisco che il lavoro che sto per fare potrebbe richiedere del tempo, e non voglio che tu debba completarlo interamente prima di poter rispondere agli input dell&#39;utente o ad altri task che potrebbero essere altrettanto importanti&amp;quot;.&lt;/p&gt;
&lt;p&gt;Questo aiuta a migliorare la reattività complessiva della pagina web, poiché il browser sarà in grado di concentrarsi su altre attività mentre il task a lungo corso è in esecuzione.&lt;/p&gt;
&lt;p&gt;E, naturalmente, questo si rivelerà estremamente utile nel lavoro di ottimizzazione della metrica &lt;a href=&quot;https://web.dev/inp/&quot;&gt;Interaction to Next Paint (INP)&lt;/a&gt;, che diventerà una Core Web Vital a partire da marzo 2024.&lt;/p&gt;
&lt;h2 id=&quot;come-usarlo&quot; tabindex=&quot;-1&quot;&gt;Come usarlo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-use-scheduler-yield-to-improve-web-page-responsiveness/#come-usarlo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ecco come si usa:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;yieldy&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Do some work...&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Yield!&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; scheduler&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;yield&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Do some more work...&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ma aspetta, si può usare solo su Chrome?
Sì, ma in alternativa puoi ripiegare sul buon vecchio &lt;code&gt;setTimeout&lt;/code&gt; per ottenere un comportamento simile.&lt;/p&gt;
&lt;p&gt;L&#39;unica differenza è che i browser che non supportano &lt;code&gt;scheduler.yield&lt;/code&gt; cederanno il controllo senza il comportamento &amp;quot;front of queue&amp;quot; (in testa alla coda), poiché &lt;code&gt;setTimeout&lt;/code&gt; sposta il lavoro rimanente in coda all&#39;elenco dei task.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// A function for shimming scheduler.yield and setTimeout:&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;yieldToMain&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Use scheduler.yield if it exists:&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;scheduler&#39;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; window &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;yield&#39;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; scheduler&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; scheduler&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;yield&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Fall back to setTimeout:&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Promise&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;resolve&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;resolve&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Example usage:&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;doWork&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Do some work:&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;yieldToMain&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Do some other work:&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;vuoi-provarlo&quot; tabindex=&quot;-1&quot;&gt;Vuoi provarlo? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-use-scheduler-yield-to-improve-web-page-responsiveness/#vuoi-provarlo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Puoi provare &lt;code&gt;scheduler.yield&lt;/code&gt; sul tuo browser abilitando il flag &amp;quot;experimental web platform features&amp;quot;, come mostrato nella figura seguente:&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/lyCjCZ-U60-648.webp 648w, https://andreaverlicchi.eu/img/lyCjCZ-U60-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/lyCjCZ-U60-648.png 648w, https://andreaverlicchi.eu/img/lyCjCZ-U60-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Funzionalità sperimentali della piattaforma web abilitate nelle impostazioni del browser Chrome&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/lyCjCZ-U60-648.png&quot; width=&quot;1296&quot; height=&quot;579&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Come abilitare le funzionalità sperimentali della piattaforma web nel browser Chrome&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Dopodiché, potrai utilizzarlo:&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/5A8b6ckAyT-648.webp 648w, https://andreaverlicchi.eu/img/5A8b6ckAyT-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/5A8b6ckAyT-648.png 648w, https://andreaverlicchi.eu/img/5A8b6ckAyT-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;scheduler.yield è presente, scheduler.yield() restituisce una Promise (pending)&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/5A8b6ckAyT-648.png&quot; width=&quot;1296&quot; height=&quot;364&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Come appare `scheduler.yield` quando viene invocato nella console dei developer tools&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;vuoi-provarlo-in-produzione&quot; tabindex=&quot;-1&quot;&gt;Vuoi provarlo in produzione? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-use-scheduler-yield-to-improve-web-page-responsiveness/#vuoi-provarlo-in-produzione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Sì, puoi farlo! Al momento della scrittura di questo articolo (settembre 2023), &lt;code&gt;scheduler.yield&lt;/code&gt; è in fase di origin trial in Chrome 115 e versioni successive. Puoi scoprire di più sulle origin trial e su come partecipare alla sperimentazione sul sito Chrome Developers: &lt;a href=&quot;https://developer.chrome.com/docs/web-platform/origin-trials/&quot;&gt;Guida introduttiva alle origin trial&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Leggi l&#39;articolo completo con una spiegazione dettagliata sul blog di Chrome Developers: &lt;a href=&quot;https://developer.chrome.com/blog/introducing-scheduler-yield-origin-trial/&quot;&gt;Introducing the scheduler.yield origin trial&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Prepararsi a Interaction to Next Paint (INP), una nuova Core Web Vital da marzo 2024</title>
		<link href="https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/"/>
		<updated>2023-07-12T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/</id>
		<content type="html">&lt;figure&gt;
	&lt;img alt=&quot;Il dipinto &#39;Creazione di Adamo&#39; di Michelangelo&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/VNBwh4cWBA-648.webp&quot; width=&quot;648&quot; height=&quot;372&quot;&gt;
	&lt;figcaption&gt;Il dipinto &quot;Creazione di Adamo&quot; di Michelangelo&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Come consulente di web performance, sono sempre attento alle novità che influenzano l&#39;esperienza utente dei siti web. Una di queste novità è l&#39;introduzione da parte di Google di una nuova metrica chiamata &lt;a href=&quot;https://web.dev/inp/&quot;&gt;Interaction to Next Paint (INP)&lt;/a&gt;. Destinata a diventare una &lt;a href=&quot;https://web.dev/cwv/&quot;&gt;Core Web Vital&lt;/a&gt; a marzo 2024, l&#39;INP è progettata per misurare il tempo impiegato da un sito web per rispondere alle interazioni degli utenti. In questo articolo approfondiremo cos&#39;è l&#39;INP, perché è importante e come le aziende possono prepararsi per garantire che i loro siti web soddisfino questa metrica fondamentale.&lt;/p&gt;
&lt;h2 id=&quot;comprendere-l-interaction-to-next-paint-inp&quot; tabindex=&quot;-1&quot;&gt;Comprendere l&#39;Interaction to Next Paint (INP) &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/#comprendere-l-interaction-to-next-paint-inp&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;L&#39;INP è un&#39;importante aggiunta alle Core Web Vitals, un insieme di metriche che Google utilizza per valutare e posizionare i siti web in base all&#39;esperienza utente.&lt;/p&gt;
&lt;p&gt;A differenza di altre metriche come il Largest Contentful Paint (LCP) e il Cumulative Layout Shift (CLS), che misurano rispettivamente il caricamento e la stabilità visiva, l&#39;INP si concentra sull&#39;interattività, ovvero sulla rapidità con cui un sito web risponde agli input degli utenti dopo il caricamento. Questa metrica quantifica il tempo necessario affinché il sito sia pronto a mostrare un aggiornamento visivo (paint) dopo l&#39;interazione dell&#39;utente, con l&#39;obiettivo di garantire un&#39;esperienza priva di ritardi percepibili.&lt;/p&gt;
&lt;h2 id=&quot;perche-l-inp-e-importante&quot; tabindex=&quot;-1&quot;&gt;Perché l&#39;INP è importante &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/#perche-l-inp-e-importante&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Nel panorama digitale odierno, le aspettative degli utenti sono più alte che mai. Le persone esigono interazioni rapide e fluide quando navigano sul web, e qualsiasi ritardo o elemento che non risponde può causare frustrazione e abbandono. L&#39;INP affronta direttamente questo problema misurando il tempo impiegato da un sito web per rispondere agli input degli utenti, un fattore cruciale per offrire un&#39;esperienza utente eccezionale.&lt;/p&gt;
&lt;p&gt;Inoltre, Google ha sottolineato l&#39;importanza delle Core Web Vitals como fattore di posizionamento per la SEO. I siti web che offrono esperienze utente migliori, misurate da queste metriche, hanno maggiori probabilità di posizionarsi più in alto nei risultati di ricerca. Con l&#39;INP destinato a diventare una Core Web Vital, le aziende che daranno priorità all&#39;interattività del proprio sito non solo miglioreranno l&#39;esperienza d&#39;uso, ma otterranno anche un vantaggio in termini di visibilità sui motori di ricerca.&lt;/p&gt;
&lt;h2 id=&quot;prepararsi-all-inp&quot; tabindex=&quot;-1&quot;&gt;Prepararsi all&#39;INP &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/#prepararsi-all-inp&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Con l&#39;avvicinarsi della scadenza di marzo 2024, le aziende devono prepararsi all&#39;inclusione dell&#39;INP come Core Web Vital. Ecco alcuni passaggi per assicurarsi che il proprio sito sia pronto:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Valutare le prestazioni attuali dell&#39;INP&lt;/strong&gt;: inizia analizzando le prestazioni attuali dell&#39;INP del tuo sito. Il modo più semplice per verificare i valori di INP del tuo sito web è tramite la &lt;a href=&quot;https://search.google.com/search-console/about&quot;&gt;Google Search Console&lt;/a&gt;. In alternativa, puoi utilizzare il &lt;a href=&quot;https://developer.chrome.com/docs/crux/&quot;&gt;Chrome User Experience Report&lt;/a&gt; (CrUX) o &lt;a href=&quot;https://pagespeed.web.dev/&quot;&gt;PageSpeed Insights&lt;/a&gt;. Misura i tuoi punteggi INP attuali e stabilisci obiettivi di miglioramento.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Migliorare l&#39;INP&lt;/strong&gt;: consulta il capitolo successivo per scoprire cosa fare per migliorare l&#39;INP sul tuo sito web.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Monitorare e iterare continuamente&lt;/strong&gt;: le prestazioni web sono un processo continuo, ed è fondamentale monitorare e misurare l&#39;INP regolarmente. Analizza costantemente le prestazioni del tuo sito, implementa ottimizzazioni e ripeti i test per assicurarti che i punteggi INP soddisfino i target desiderati. Consulta regolarmente la documentazione per sviluppatori di Google e i forum della community per rimanere aggiornato sulle best practice.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;come-migliorare-l-inp&quot; tabindex=&quot;-1&quot;&gt;Come migliorare l&#39;INP &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/#come-migliorare-l-inp&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Entriamo ora un po&#39; più nel tecnico. Ci sono 3 tipi di azioni che puoi intraprendere per migliorare l&#39;INP sul tuo sito web: evitare o spezzare i task lunghi (long tasks), evitare il JavaScript non necessario ed evitare aggiornamenti di rendering troppo grandi.&lt;/p&gt;
&lt;h3 id=&quot;evitare-o-spezzare-i-task-lunghi&quot; tabindex=&quot;-1&quot;&gt;Evitare o spezzare i task lunghi &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/#evitare-o-spezzare-i-task-lunghi&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;I task (compiti) sono singole unità di lavoro eseguite dal browser. Includono il rendering, il calcolo del layout, il parsing, la compilazione e l&#39;esecuzione degli script. Quando i task diventano &amp;quot;task lunghi&amp;quot; (long tasks)—ovvero durano 50 millisecondi o più—bloccano il thread principale (main thread), impedendogli di rispondere rapidamente agli input dell&#39;utente.&lt;/p&gt;
&lt;p&gt;Un&#39;altra opzione è considerare l&#39;uso di API come &lt;code&gt;isInputPending&lt;/code&gt; e la Scheduler API. &lt;code&gt;isInputPending&lt;/code&gt; è una funzione che restituisce un valore booleano indicante se c&#39;è un input utente in attesa. Se restituisce vero, puoi cedere il controllo (yield) al thread principale in modo che possa gestire l&#39;interazione pendente. &lt;a href=&quot;https://web.dev/optimize-long-tasks/#yield-only-when-necessary&quot;&gt;Scopri di più su &lt;code&gt;isInputPending&lt;/code&gt;&lt;/a&gt; per cedere il controllo solo quando necessario.&lt;/p&gt;
&lt;p&gt;La Scheduler API è un approccio più avanzato, che consente di pianificare il lavoro in base a un sistema di priorità che tiene conto se l&#39;attività in corso sia visibile all&#39;utente o in background. &lt;a href=&quot;https://web.dev/optimize-long-tasks/#a-dedicated-scheduler-api&quot;&gt;Scopri di più sulla Scheduler API&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Spezzando i task lunghi, offri al browser maggiori opportunità di inserire tempestivamente il lavoro critico visibile all&#39;utente, come la gestione delle interazioni e i relativi aggiornamenti di rendering.&lt;/p&gt;
&lt;h3 id=&quot;evitare-il-javascript-superfluo&quot; tabindex=&quot;-1&quot;&gt;Evitare il JavaScript superfluo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/#evitare-il-javascript-superfluo&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Non c&#39;è dubbio: i siti web stanno &lt;a href=&quot;https://almanac.httparchive.org/en/2022/javascript#how-much-javascript-do-we-load&quot;&gt;inviando più JavaScript&lt;/a&gt; che mai, e la tendenza non sembra destinata a cambiare a breve. Quando invii troppo JavaScript, crei un ambiente in cui i vari task competono per l&#39;attenzione del thread principale. Questo può influire negativamente sulla reattività del tuo sito, specialmente durante la cruciale fase di avvio (startup).&lt;/p&gt;
&lt;p&gt;Tuttavia, questo non è un problema irrisolvibile. Hai a disposizione diverse opzioni:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Usa lo strumento Coverage in Chrome DevTools per individuare il codice inutilizzato nelle risorse del tuo sito. Riducendo le dimensioni delle risorse necessarie all&#39;avvio, farai in modo che il sito passi meno tempo a fare il parsing e a compilare il codice, a tutto vantaggio di una migliore esperienza utente iniziale. &lt;a href=&quot;https://developer.chrome.com/docs/devtools/coverage/&quot;&gt;Scopri lo strumento Coverage&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A volte il codice inutilizzato trovato con lo strumento Coverage è contrassegnato come tale semplicemente perché non è stato eseguito all&#39;avvio, ma è comunque necessario per funzionalità future. Questo è codice che puoi spostare in un bundle separato tramite il code splitting (divisione del codice). &lt;a href=&quot;https://web.dev/reduce-javascript-payloads-with-code-splitting/&quot;&gt;Scopri di più sul code splitting&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Se utilizzi un tag manager, assicurati di controllare periodicamente i tag per verificare che siano ottimizzati o se siano ancora effettivamente necessari. I vecchi tag con codice inutilizzato possono essere rimossi per rendere il JavaScript del tag manager più leggero ed efficiente. &lt;a href=&quot;https://web.dev/tag-best-practices/&quot;&gt;Ulteriori best practice per i tag manager&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;evitare-aggiornamenti-di-rendering-di-grandi-dimensioni&quot; tabindex=&quot;-1&quot;&gt;Evitare aggiornamenti di rendering di grandi dimensioni &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/#evitare-aggiornamenti-di-rendering-di-grandi-dimensioni&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Il JavaScript non è l&#39;unico fattore che può influire sulla reattività del tuo sito. Il rendering stesso può essere un&#39;attività molto onerosa e, quando si verificano aggiornamenti di rendering di grandi dimensioni, questi possono ostacolare la capacità del sito di rispondere tempestivamente agli input dell&#39;utente.&lt;/p&gt;
&lt;p&gt;Ottimizzare il lavoro di rendering non è un processo lineare e spesso dipende da ciò che si vuole ottenere. Ciononostante, ci sono alcune accortezze che puoi adottare per garantire che gli aggiornamenti di rendering siano contenuti e non si trasformino in task lunghi:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Evita di usare &lt;code&gt;requestAnimationFrame()&lt;/code&gt; per attività non visive. Le chiamate a &lt;code&gt;requestAnimationFrame()&lt;/code&gt; vengono gestite durante la fase di rendering dell&#39;event loop e, se si esegue troppo lavoro in questa fase, gli aggiornamenti visivi possono subire ritardi. È fondamentale che qualsiasi operazione eseguita all&#39;interno di &lt;code&gt;requestAnimationFrame()&lt;/code&gt; sia riservata strettamente ad attività legate agli aggiornamenti di rendering.&lt;/li&gt;
&lt;li&gt;Mantieni ridotte le dimensioni del DOM. Esiste una correlazione diretta tra la dimensione del DOM e l&#39;onerosità del calcolo del layout. Quando il renderer deve aggiornare il layout per un DOM molto grande, il lavoro richiesto per ricalcolarlo aumenta in modo significativo. &lt;a href=&quot;https://developer.chrome.com/docs/lighthouse/performance/dom-size/&quot;&gt;Evitare un DOM dalle dimensioni eccessive&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Usa il CSS containment. Questa tecnica si basa sulla proprietà CSS &lt;code&gt;contain&lt;/code&gt;, che fornisce istruzioni al browser su come gestire il layout per il contenitore su cui è applicata, arrivando persino a isolare l&#39;ambito del layout e del rendering a una radice specifica nel DOM. Non è sempre un processo semplice, ma isolando le aree con layout complessi si evita di eseguire per esse lavori di layout e rendering non necessari. &lt;a href=&quot;https://developer.mozilla.org/docs/Web/CSS/CSS_Containment&quot;&gt;Scopri di più sul CSS Containment&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Con l&#39;Interaction to Next Paint (INP) destinato a diventare una Core Web Vital a marzo 2024, le aziende dovrebbero iniziare a dare priorità all&#39;interattività del proprio sito web per offrire un&#39;esperienza utente eccezionale e migliorare il posizionamento sui motori di ricerca.&lt;/p&gt;
&lt;p&gt;Valutando le prestazioni INP attuali, ottimizzando l&#39;interattività e monitorando e iterando costantemente, le aziende possono prepararsi al meglio a questo cambiamento.&lt;/p&gt;
&lt;p&gt;Adottare l&#39;INP come metrica fondamentale per le prestazioni non porterà solo benefici agli utenti, ma contribuirà anche al successo a lungo termine della propria presenza online.&lt;/p&gt;
&lt;h2 id=&quot;hai-bisogno-di-aiuto&quot; tabindex=&quot;-1&quot;&gt;Hai bisogno di aiuto? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/preparing-for-interaction-to-next-paint-inp-core-web-vital-google/#hai-bisogno-di-aiuto&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se desideri saperne di più sull&#39;INP, su come ottimizzarlo o se hai bisogno di una consulenza sulle prestazioni web, non esitare a &lt;a href=&quot;https://andreaverlicchi.eu/contact/&quot;&gt;contattarmi&lt;/a&gt;.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Talk: Come e perché ($) migliorare le prestazioni web nel 2023</title>
		<link href="https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/"/>
		<updated>2023-06-16T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/</id>
		<content type="html">&lt;p&gt;Nel 2023 ho parlato di web performance in conferenze, Google Developer Groups (GDG) e meetup locali in tutta Europa. Il titolo di questo talk è &amp;quot;Come e perché ($) migliorare le prestazioni web: consigli pratici per il 2023&amp;quot;.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/ofRvkAJXGGw?si=2WGVWiQhq2ckqNY_&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;La prima parte del talk illustra i motivi per cui ottimizzare le prestazioni web, mentre la seconda parte spiega come farlo, con consigli pratici provenienti &lt;a href=&quot;https://web.dev/top-cwv-2023/&quot;&gt;da Google&lt;/a&gt; e basati sui dati raccolti nel &lt;a href=&quot;https://almanac.httparchive.org/en/2022/performance&quot;&gt;capitolo dedicato alle performance&lt;/a&gt; del &lt;a href=&quot;https://almanac.httparchive.org/en/2022/&quot;&gt;Web Almanac 2022&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Di seguito trovi le slide del mio talk, sia in inglese che in italiano.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://andreaverlicchi.eu/pdf/how-why-improve-web-performance-practical-tips-2023.pdf&quot;&gt;Slides in English&lt;/a&gt; 🇬🇧 · &lt;a href=&quot;https://andreaverlicchi.eu/pdf/come-perche-migliorare-prestazioni-web-consigli-pratici-2023.pdf&quot;&gt;Slide in Italiano&lt;/a&gt; 🇮🇹&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;waysconf-cracovia-4-settembre-2023&quot; tabindex=&quot;-1&quot;&gt;WaysConf, Cracovia 🇵🇱 – &lt;time datetime=&quot;2023-09-04&quot;&gt;4 settembre 2023&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/#waysconf-cracovia-4-settembre-2023&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/RnlMzWFgWG-648.webp 648w, https://andreaverlicchi.eu/img/RnlMzWFgWG-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/RnlMzWFgWG-648.png 648w, https://andreaverlicchi.eu/img/RnlMzWFgWG-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi sul palco di WaysConf Cracovia&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/RnlMzWFgWG-648.png&quot; width=&quot;1296&quot; height=&quot;864&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io che spiego la differenza tra strumenti di laboratorio (lab) e di monitoraggio reale degli utenti (RUM) al WaysConf 2023&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=ofRvkAJXGGw&quot;&gt;📺 Video&lt;/a&gt; · &lt;a href=&quot;https://www.waysconf.com/lecture/how-and-why-to-improve-web-performance-in-2023&quot;&gt;Pagina del talk sul sito della conferenza&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;dev-bcn-conference-barcellona-4-luglio-2023&quot; tabindex=&quot;-1&quot;&gt;Dev BCN Conference, Barcellona 🇪🇸 – &lt;time datetime=&quot;2023-07-04&quot;&gt;4 luglio 2023&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/#dev-bcn-conference-barcellona-4-luglio-2023&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/sR1XTNBOBC-648.webp 648w, https://andreaverlicchi.eu/img/sR1XTNBOBC-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/sR1XTNBOBC-648.png 648w, https://andreaverlicchi.eu/img/sR1XTNBOBC-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi mentre mostra una slide sulle Core Web Vitals e sulla nuova metrica Interaction to Next Paint alla conferenza Dev BCN&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/sR1XTNBOBC-648.png&quot; width=&quot;1296&quot; height=&quot;863&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io che presento una slide sulle Core Web Vitals sul palco della conferenza Dev BCN&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://www.devbcn.com/talk/457013&quot;&gt;Pagina del talk sul sito della conferenza&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;devfest-vienna-14-ottobre-2023&quot; tabindex=&quot;-1&quot;&gt;DevFest, Vienna 🇦🇹 – &lt;time datetime=&quot;2023-10-14&quot;&gt;14 ottobre 2023&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/#devfest-vienna-14-ottobre-2023&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;img alt=&quot;Andrea Verlicchi sul palco del DevFest Vienna, 2023&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/WnICdy0177-648.webp&quot; width=&quot;1296&quot; height=&quot;863&quot; srcset=&quot;https://andreaverlicchi.eu/img/WnICdy0177-648.webp 648w, https://andreaverlicchi.eu/img/WnICdy0177-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;
  &lt;figcaption&gt;Io sul palco che spiego cos&#39;è Interaction to Next Paint&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://devfest.at/schedule/&quot;&gt;Programma del DevFest&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;google-developer-group-monaco-di-baviera-7-giugno-2023&quot; tabindex=&quot;-1&quot;&gt;Google Developer Group, Monaco di Baviera 🇩🇪 – &lt;time datetime=&quot;2023-06-07&quot;&gt;7 giugno 2023&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/#google-developer-group-monaco-di-baviera-7-giugno-2023&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/rZOIAdVBpk-648.webp 648w, https://andreaverlicchi.eu/img/rZOIAdVBpk-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/rZOIAdVBpk-648.jpeg 648w, https://andreaverlicchi.eu/img/rZOIAdVBpk-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea che parla davanti al pubblico, inquadratura dalla platea&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/rZOIAdVBpk-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io che parlo davanti al pubblico negli uffici Google di Monaco di Baviera&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://gdg.community.dev/events/details/google-gdg-munich-presents-web-performance-meetup/&quot;&gt;Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;google-developer-group-firenze-25-maggio-2023&quot; tabindex=&quot;-1&quot;&gt;Google Developer Group, Firenze 🇮🇹 – &lt;time datetime=&quot;2023-05-25&quot;&gt;25 maggio 2023&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/#google-developer-group-firenze-25-maggio-2023&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/ZmvXQ0KrMH-648.webp 648w, https://andreaverlicchi.eu/img/ZmvXQ0KrMH-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/ZmvXQ0KrMH-648.jpeg 648w, https://andreaverlicchi.eu/img/ZmvXQ0KrMH-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea che parla davanti al pubblico, inquadratura laterale&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/ZmvXQ0KrMH-648.jpeg&quot; width=&quot;1296&quot; height=&quot;958&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io che parlo davanti al pubblico a Nana Bianca, Firenze&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Titolo in italiano: &amp;quot;Come e perché ($) migliorare le Prestazioni Web: consigli pratici per il 2023&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gdg.community.dev/events/details/google-gdg-firenze-presents-come-e-perche-migliorare-le-prestazioni-web/&quot;&gt;Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;bologna-js-google-developer-group-bologna-5-aprile-2023&quot; tabindex=&quot;-1&quot;&gt;Bologna JS + Google Developer Group, Bologna 🇮🇹 – &lt;time datetime=&quot;2023-04-05&quot;&gt;5 aprile 2023&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/#bologna-js-google-developer-group-bologna-5-aprile-2023&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/Sa4w-8TfNq-648.webp 648w, https://andreaverlicchi.eu/img/Sa4w-8TfNq-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/Sa4w-8TfNq-648.jpeg 648w, https://andreaverlicchi.eu/img/Sa4w-8TfNq-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea che parla davanti al pubblico, la slide mostra il testo &#39;Assicurati che le pagine siano idonee per la cache back/forward (bfcache)&#39;&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/Sa4w-8TfNq-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io sul palco durante l&#39;evento a Bologna&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Titolo in italiano: &amp;quot;Come e perché ($) migliorare le Prestazioni Web: consigli pratici per il 2023&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=_UuExM3NhaA&quot;&gt;📺 Video&lt;/a&gt; · &lt;a href=&quot;https://www.meetup.com/it-IT/bologna-js-meetup/events/292424299/&quot;&gt;Pagina dell&#39;evento Bologna JS&lt;/a&gt; · &lt;a href=&quot;https://gdg.community.dev/events/details/google-gdg-bologna-presents-come-e-perche-migliorare-le-prestazioni-web-consigli-pratici-per-il-2023/&quot;&gt;Pagina dell&#39;evento GDG&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;dev-romagna-imola-22-marzo-2023&quot; tabindex=&quot;-1&quot;&gt;Dev Romagna, Imola 🇮🇹 – &lt;time datetime=&quot;2023-03-22&quot;&gt;22 marzo 2023&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/#dev-romagna-imola-22-marzo-2023&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/S9gCW7-iw_-648.webp 648w, https://andreaverlicchi.eu/img/S9gCW7-iw_-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/S9gCW7-iw_-648.jpeg 648w, https://andreaverlicchi.eu/img/S9gCW7-iw_-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;La location e il pubblico durante la presentazione del gruppo Dev Romagna&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/S9gCW7-iw_-648.jpeg&quot; width=&quot;1296&quot; height=&quot;972&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;La location e il pubblico durante la presentazione del gruppo Dev Romagna&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Titolo in italiano: &amp;quot;Come e perché ($) migliorare le Prestazioni Web: consigli pratici per il 2023&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.meetup.com/it-IT/devromagna/events/291862771&quot;&gt;Pagina dell&#39;evento Dev Romagna&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;google-developer-group-torino-23-febbraio-2023&quot; tabindex=&quot;-1&quot;&gt;Google Developer Group, Torino 🇮🇹 – &lt;time datetime=&quot;2023-02-23&quot;&gt;23 febbraio 2023&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/#google-developer-group-torino-23-febbraio-2023&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/jEqhzoxgzj-648.webp 648w, https://andreaverlicchi.eu/img/jEqhzoxgzj-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/jEqhzoxgzj-648.jpeg 648w, https://andreaverlicchi.eu/img/jEqhzoxgzj-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi mentre mostra una slide: un miglioramento del tempo di caricamento di 1 secondo può portare a -14% di bounce rate, +13% di conversion rate&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/jEqhzoxgzj-648.jpeg&quot; width=&quot;1296&quot; height=&quot;842&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Un miglioramento di 1 secondo nel tempo di caricamento può migliorare il tasso di conversione del sito e ridurre la frequenza di rimbalzo&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/_Yiranwk6n-648.webp 648w, https://andreaverlicchi.eu/img/_Yiranwk6n-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/jpeg&quot; srcset=&quot;https://andreaverlicchi.eu/img/_Yiranwk6n-648.jpeg 648w, https://andreaverlicchi.eu/img/_Yiranwk6n-1296.jpeg 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi che parla davanti alla platea del GDG Torino nel febbraio 2023&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/_Yiranwk6n-648.jpeg&quot; width=&quot;1296&quot; height=&quot;446&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;La splendida platea a Torino&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Titolo in italiano: &amp;quot;Web Talks: from Design to Performance&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gdg.community.dev/events/details/google-gdg-torino-presents-web-talks-from-design-to-performance/&quot;&gt;Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;bologna-front-end-bologna-15-febbraio-2023&quot; tabindex=&quot;-1&quot;&gt;Bologna Front-End, Bologna 🇮🇹 – &lt;time datetime=&quot;2023-02-15&quot;&gt;15 febbraio 2023&lt;/time&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-and-why-to-optimize-web-performance-practical-tips-2023/#bologna-front-end-bologna-15-febbraio-2023&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/9qzNBCbIdP-648.webp 648w, https://andreaverlicchi.eu/img/9qzNBCbIdP-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/9qzNBCbIdP-648.png 648w, https://andreaverlicchi.eu/img/9qzNBCbIdP-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi mentre mostra una slide introduttiva all&#39;evento Bologna Front-End nel febbraio 2023&quot; loading=&quot;lazy&quot; src=&quot;https://andreaverlicchi.eu/img/9qzNBCbIdP-648.png&quot; width=&quot;1296&quot; height=&quot;729&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Io sul palco dell&#39;evento Bologna Front-End&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Titolo in italiano: &amp;quot;Web performance per tutti&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=eBBGYyKd7lg&quot;&gt;📺 Video&lt;/a&gt; · &lt;a href=&quot;https://www.meetup.com/it-IT/bologna-front-end/events/291336433/&quot;&gt;Pagina dell&#39;evento&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Sono un Google Developer Expert per le Web Performance</title>
		<link href="https://andreaverlicchi.eu/it/blog/google-developer-expert-gde-web-performance/"/>
		<updated>2022-12-06T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/google-developer-expert-gde-web-performance/</id>
		<content type="html">&lt;p&gt;Nel dicembre 2023 sono diventato un Google Developer Expert (GDE) per le Web Performance. &lt;a href=&quot;https://developers.google.com/community/experts&quot;&gt;Google Developer Experts&lt;/a&gt; è un programma di Google per creare una rete globale di professionisti, influencer e leader di pensiero, e consentire loro di condividere le proprie conoscenze con la community degli sviluppatori, ad esempio parlando a eventi, condividendo best practice e offrendo mentorship ad altri.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/V0OR3WaxYk-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Experts&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/V0OR3WaxYk-648.png&quot; width=&quot;648&quot; height=&quot;367&quot;&gt;&lt;/picture&gt;
	&lt;figcaption&gt;Il logo di Google Developer Experts&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Entrando a far parte del programma GDE, mi sono unito a una community di tecnologi appassionati da tutto il mondo, il che mi permette di fare rete con loro e con i team di Google.&lt;/p&gt;
&lt;p&gt;Oltre ad essere &lt;a href=&quot;https://developers.google.com/community/experts/directory/profile/profile-andrea-verlicchi&quot;&gt;inserito&lt;/a&gt; nella directory dei Google Developer Experts, avrò accesso anticipato ai prodotti e alle novità relative alle web performance.&lt;/p&gt;
&lt;p&gt;Sentiti libero di &lt;a href=&quot;https://andreaverlicchi.eu/contact/&quot;&gt;contattarmi&lt;/a&gt; se vuoi fare due chiacchiere sul programma o sulle web performance.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>aspect-ratio: Un modo moderno per riservare spazio a immagini e contenuti asincroni nel responsive design</title>
		<link href="https://andreaverlicchi.eu/it/blog/aspect-ratio-modern-reserve-space-lazy-images-async-content-responsive-design/"/>
		<updated>2022-11-19T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/aspect-ratio-modern-reserve-space-lazy-images-async-content-responsive-design/</id>
		<content type="html">&lt;p&gt;Per evitare lo &lt;strong&gt;spostamento del layout&lt;/strong&gt; (layout shifting) e ottimizzare la metrica &lt;a href=&quot;https://web.dev/cls/&quot;&gt;Cumulative Layout Shift&lt;/a&gt; delle &lt;a href=&quot;https://web.dev/vitals/&quot;&gt;Core Web Vitals&lt;/a&gt; nelle tue pagine web, devi riservare spazio per qualsiasi &lt;strong&gt;contenuto che potrebbe essere renderizzato in un secondo momento&lt;/strong&gt;. Questo è il caso di immagini, video e qualsiasi contenuto caricato in modo asincrono (ad esempio tramite chiamate AJAX). Ecco un nuovo modo per farlo.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/ks3J_BLdt9-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Diversi rapporti d&#39;aspetto rappresentati in quadrati e rettangoli. 1/1, 4/3, 16/9, 2/3&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/ks3J_BLdt9-648.png&quot; width=&quot;648&quot; height=&quot;432&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;h2 id=&quot;il-buon-vecchio-metodo&quot; tabindex=&quot;-1&quot;&gt;Il buon vecchio metodo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/aspect-ratio-modern-reserve-space-lazy-images-async-content-responsive-design/#il-buon-vecchio-metodo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il metodo tradizionale per riservare spazio alle immagini consiste nell&#39;utilizzare il trucco del padding verticale (padding-bottom hack).&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image-wrapper&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;An image&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.image-wrapper&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;padding-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 150%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;/* 👆 image height / width * 100% */&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; relative&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.image&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;il-metodo-moderno-1-aspect-ratio-mappato&quot; tabindex=&quot;-1&quot;&gt;Il metodo moderno 1 - &lt;code&gt;aspect-ratio&lt;/code&gt; mappato &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/aspect-ratio-modern-reserve-space-lazy-images-async-content-responsive-design/#il-metodo-moderno-1-aspect-ratio-mappato&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il metodo moderno e più semplice consiste nel definire implicitamente un rapporto d&#39;aspetto larghezza/altezza &lt;a href=&quot;https://twitter.com/addyosmani/status/1276779799198007301&quot;&gt;impostando gli attributi width e height su immagini e video&lt;/a&gt;. Questo approccio è noto come &amp;quot;mapped aspect-ratio&amp;quot;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;An image&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;200&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;300&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;video&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;A video&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;video.mp4&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;1600&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;900&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;...&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;video&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* Modern browser stylesheets will add a default
  aspect ratio based on the element&#39;s existing
  width and height attributes */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;img,
video&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;aspect-ratio&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;width&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; / &lt;span class=&quot;token function&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;height&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;La buona notizia è che sia i browser basati su Chromium (Chrome, Microsoft Edge e Opera), sia Firefox e Safari (a partire dalla versione 14) ora supportano l&#39;&lt;code&gt;aspect-ratio&lt;/code&gt; mappato! Di conseguenza, la stragrande maggioranza dei browser è coperta, mentre Internet Explorer sta scomparendo e Microsoft Edge si sta diffondendo.&lt;/p&gt;
&lt;p&gt;Tuttavia, ci sono alcune accortezze da considerare quando si utilizza il lazy loading gestito da JavaScript.&lt;/p&gt;
&lt;h3 id=&quot;demo&quot; tabindex=&quot;-1&quot;&gt;Demo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/aspect-ratio-modern-reserve-space-lazy-images-async-content-responsive-design/#demo&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Ho creato una serie di demo su Codepen per testare l&#39;&lt;code&gt;aspect-ratio&lt;/code&gt; mappato in diversi scenari.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Caso d&#39;uso&lt;/th&gt;
&lt;th&gt;Funziona?&lt;/th&gt;
&lt;th&gt;Demo&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Lazy loading nativo (nessun placeholder richiesto)&lt;/td&gt;
&lt;td&gt;🟢 Sì&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;https://codepen.io/verlok/pen/ExPwzGO&quot;&gt;Demo&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lazy loading Javascript (nessun placeholder, senza fix &lt;code&gt;display&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;🔴 No&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;https://codepen.io/verlok/pen/bGEYyZe&quot;&gt;Demo&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lazy loading Javascript (nessun placeholder, con fix &lt;code&gt;display&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;🟢 Sì&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;https://codepen.io/verlok/pen/RwKeoBX&quot;&gt;Demo&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lazy loading Javascript (placeholder SVG, senza fix &lt;code&gt;display&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;🟢 Sì&lt;/td&gt;
&lt;td&gt;&lt;a href=&quot;https://codepen.io/verlok/pen/zYNmoxz&quot;&gt;Demo&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Con &amp;quot;fix &lt;code&gt;display&lt;/code&gt;&amp;quot; intendo che ho dovuto impostare la proprietà &lt;code&gt;display&lt;/code&gt; delle immagini su &lt;code&gt;block&lt;/code&gt;, poiché lasciare il valore predefinito (&lt;code&gt;inline-block&lt;/code&gt;) non funzionava correttamente per le immagini caricate in lazy loading tramite JavaScript.&lt;/p&gt;
&lt;p&gt;Con &amp;quot;Funziona?&amp;quot; intendo se il browser ha riservato lo spazio per le immagini prima del loro effettivo caricamento.
Per verificare tu stesso il funzionamento, usa i developer tools del tuo browser per disabilitare la cache ed emulare una velocità di rete &amp;quot;slow 3G&amp;quot;.
Dovresti notare che lo spazio viene riservato &lt;em&gt;prima&lt;/em&gt; che le immagini inizino a caricarsi, posizionando il paragrafo di testo molto al di sotto delle immagini.&lt;/p&gt;
&lt;h2 id=&quot;il-metodo-moderno-2-aspect-ratio-esplicito&quot; tabindex=&quot;-1&quot;&gt;Il metodo moderno 2 - &lt;code&gt;aspect-ratio&lt;/code&gt; esplicito &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/aspect-ratio-modern-reserve-space-lazy-images-async-content-responsive-design/#il-metodo-moderno-2-aspect-ratio-esplicito&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In alternativa, è possibile impostare esplicitamente il rapporto d&#39;aspetto direttamente nel codice CSS utilizzando &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio&quot;&gt;la regola CSS aspect-ratio&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;async&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Content is loading...&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;aspect-ratio&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 16/9&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;s&gt;Sfortunatamente, al momento (aprile 2021) questa funzionalità è supportata solo dai browser Chromium. Non sappiamo ancora se e quando sarà supportata nelle future versioni di Safari.&lt;/s&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Aggiornamento di novembre 2021:&lt;/strong&gt; questa proprietà è ora &lt;a href=&quot;https://caniuse.com/mdn-css_properties_aspect-ratio&quot;&gt;supportata&lt;/a&gt; da tutte le ultime versioni di tutti i browser (tranne Internet Explorer, ma... vabbè).&lt;/p&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/aspect-ratio-modern-reserve-space-lazy-images-async-content-responsive-design/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Evviva! Oggi è finalmente possibile utilizzare l&#39;&lt;code&gt;aspect-ratio&lt;/code&gt; mappato per riservare lo spazio ai tuoi contenuti caricati in lazy loading, come immagini e video!&lt;/p&gt;
&lt;p&gt;Basta impostare gli attributi &lt;code&gt;width&lt;/code&gt; e &lt;code&gt;height&lt;/code&gt; sulle immagini e scegliere una delle seguenti tre modalità:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Usare il lazy loading nativo con &lt;code&gt;loading=&amp;quot;lazy&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Usare il lazy loading JavaScript senza placeholder, ma applicando &lt;code&gt;display: block&lt;/code&gt; alle immagini&lt;/li&gt;
&lt;li&gt;Usare il lazy loading JavaScript con i placeholder&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Non vedo l&#39;ora di sapere come sei riuscito a ridurre il &lt;a href=&quot;https://web.dev/cls&quot;&gt;CLS&lt;/a&gt; delle tue pagine usando queste tecniche.
Per favore &lt;a href=&quot;https://andreaverlicchi.eu/contact/&quot;&gt;contattami&lt;/a&gt; e fammi sapere!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Contro lo streaming online dei meetup locali</title>
		<link href="https://andreaverlicchi.eu/it/blog/against-online-streaming-of-local-meetups/"/>
		<updated>2022-11-19T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/against-online-streaming-of-local-meetups/</id>
		<content type="html">&lt;p&gt;Mi piace partecipare ai meetup locali. Sono informativi, divertenti e allo stesso tempo stimolanti dal punto di vista sociale. A volte viene chiesto agli organizzatori dei meetup di trasmettere gli eventi online. Sarebbe una bella funzionalità, ma a mio parere farebbe più male che bene alla community. Vi spiego perché.&lt;/p&gt;
&lt;img alt=&quot;Un disegno di un computer con persone che fanno una riunione online&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/qZQpvuYqHk-648.webp&quot; width=&quot;648&quot; height=&quot;289&quot;&gt;
&lt;p&gt;Ascoltare l&#39;argomento del meetup di persona, insieme ad altre persone che condividono i tuoi stessi interessi, concentrati sul relatore e sulle sue slide, è un tipo di esperienza. Guardare lo stesso evento da casa, davanti a uno schermo, da soli, con distrazioni che richiamano la tua attenzione e lontano da dove si svolge l&#39;evento, è un&#39;esperienza decisamente più debole.&lt;/p&gt;
&lt;p&gt;Potresti facilmente trovare articoli di blog o tutorial online sullo stesso argomento del meetup, molto probabilmente di qualità superiore. Il vero valore di un meetup in presenza risiede nella socializzazione, nel fare rete, nello scambio di idee che avviene prima e dopo il talk e, se si vuole, in pizzeria subito dopo.&lt;/p&gt;
&lt;p&gt;Inoltre, il fatto che un evento sia trasmesso anche online indebolisce l&#39;evento in presenza. Qualcuno potrebbe pensare: &amp;quot;Ma chi me lo fa fare di andare in città, posso guardarlo in streaming&amp;quot;. E poi, quando arriva il momento: &amp;quot;Ma chi me lo fa fare di guardarlo in diretta, guarderò la registrazione più tardi&amp;quot;. E infine: &amp;quot;Ah, perché dovrei guardare la registrazione, cercherò un tutorial online&amp;quot;. Forse.&lt;/p&gt;
&lt;p&gt;Se parliamo di conferenze, tuttavia, ci sono alcune differenze. Le conferenze possono essere online, ma penso che debbano essere o online o offline, non entrambe le cose. Le conferenze online possono avere un pubblico più ampio, persino mondiale, e possono ridurre i costi per i partecipanti, oltre a essere più accessibili per chi ha disabilità motorie. Tuttavia, a mio parere, le conferenze in presenza rimangono le migliori, per gli stessi motivi: stare insieme a persone che condividono i tuoi stessi interessi, scambiare idee, ecc.&lt;/p&gt;
&lt;p&gt;E tu cosa ne pensi? Sentiti libero di &lt;a href=&quot;https://andreaverlicchi.eu/contact/&quot;&gt;contattarmi&lt;/a&gt; e farmelo sapere!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Abbiamo ancora bisogno delle librerie di lazy loading e di `data-src`?</title>
		<link href="https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/"/>
		<updated>2022-11-13T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/</id>
		<content type="html">&lt;p&gt;In passato, quando il supporto dei browser per il &lt;a href=&quot;https://web.dev/browser-level-image-lazy-loading/&quot;&gt;lazy loading nativo&lt;/a&gt; non era diffuso, la best practice consisteva nell&#39;usare gli attributi &lt;code&gt;data-src&lt;/code&gt; e una libreria JavaScript come la mia &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt; per caricare le immagini man mano che entravano nella viewport. Questa è ancora la best practice oggi?&lt;/p&gt;
&lt;img alt=&quot;Abbiamo ancora bisogno delle librerie di lazy loading e di data-src nel 2022&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/fEKUhQxFxu-648.webp&quot; width=&quot;648&quot; height=&quot;324&quot;&gt;
&lt;h2 id=&quot;cos-e-il-lazy-loading&quot; tabindex=&quot;-1&quot;&gt;Cos&#39;è il lazy loading? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/#cos-e-il-lazy-loading&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Il lazy loading delle immagini&lt;/strong&gt; è una tecnica per &lt;strong&gt;rimandare il caricamento delle immagini &lt;em&gt;below-the-fold&lt;/em&gt;&lt;/strong&gt; (sotto la piega) fino a quando non stanno per entrare nella viewport (la parte visibile della pagina). Questa tecnica fa risparmiare larghezza di banda, riduce i costi del CDN, abbassa l&#39;impronta di carbonio del sito web e migliora il tempo di rendering della pagina, in particolare il &lt;a href=&quot;https://web.dev/lcp/&quot;&gt;Largest Contentful Paint&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;lazy-loading-delle-immagini-gestito-da-javascript&quot; tabindex=&quot;-1&quot;&gt;Lazy loading delle immagini gestito da JavaScript &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/#lazy-loading-delle-immagini-gestito-da-javascript&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Tradizionalmente, il lazy loading delle immagini comportava la sostituzione dell&#39;attributo &lt;code&gt;src&lt;/code&gt; con un attributo &lt;code&gt;data-src&lt;/code&gt; e l&#39;uso di JavaScript per rilevare quando le immagini si avvicinavano alla viewport, per poi copiare gli attributi &lt;code&gt;data&lt;/code&gt; in quelli corretti, avviando così il loro caricamento differito.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;turtle.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Lazy turtle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;lazy-loading-nativo&quot; tabindex=&quot;-1&quot;&gt;Lazy loading nativo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/#lazy-loading-nativo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Con il lazy loading nativo, &lt;abbr title=&quot;anche noto come&quot;&gt;detto anche&lt;/abbr&gt; &lt;a href=&quot;https://web.dev/browser-level-image-lazy-loading/&quot;&gt;lazy loading a livello di browser&lt;/a&gt;, basta aggiungere l&#39;attributo &lt;code&gt;loading=&amp;quot;lazy&amp;quot;&lt;/code&gt; al tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;turtle.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Lazy turtle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;loading&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Questo funziona su &lt;a href=&quot;https://caniuse.com/loading-lazy-attr&quot;&gt;tutti i browser moderni&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;abbiamo-ancora-bisogno-del-lazy-loading-gestito-da-javascript&quot; tabindex=&quot;-1&quot;&gt;Abbiamo ancora bisogno del lazy loading gestito da JavaScript? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/#abbiamo-ancora-bisogno-del-lazy-loading-gestito-da-javascript&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;No, a meno che non si desideri un maggiore controllo sul processo di lazy loading.&lt;/p&gt;
&lt;p&gt;Vediamo quali sono i casi in cui ha senso usare il lazy loading guidato da JavaScript invece di affidarsi solo a &lt;code&gt;loading=&amp;quot;lazy&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;1-supportare-gli-utenti-con-connessioni-lente-o-instabili&quot; tabindex=&quot;-1&quot;&gt;1. Supportare gli utenti con connessioni lente o instabili &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/#1-supportare-gli-utenti-con-connessioni-lente-o-instabili&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Le librerie JavaScript come &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt; possono annullare il download delle immagini che escono dalla viewport e riprovare i download se interrotti, migliorando l&#39;esperienza utente sulle connessioni lente.&lt;/p&gt;
&lt;p&gt;Un caso d&#39;uso tipico è:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;pagine con molte immagini +&lt;/li&gt;
&lt;li&gt;utenti con connessioni lente +&lt;/li&gt;
&lt;li&gt;scorrimento veloce verso il basso&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Il lazy loading nativo fa sì che i browser scarichino le immagini in lazy loading dall&#39;alto verso il basso, con conseguente ritardo nel mostrare le immagini in fondo.&lt;/p&gt;
&lt;p&gt;Le librerie Javascript come &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt; annulleranno il download delle immagini che escono dalla viewport, mantenendo la larghezza di banda dell&#39;utente concentrata sulle immagini attualmente visibili.&lt;/p&gt;
&lt;p&gt;Un altro caso d&#39;uso è:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;download delle immagini in corso&lt;/li&gt;
&lt;li&gt;connessione di rete interrotta&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt; riproverà a scaricare quelle immagini una volta ripristinata la connessione.&lt;/p&gt;
&lt;p&gt;Puoi provare queste funzionalità in una qualsiasi delle &lt;a href=&quot;https://verlok.github.io/vanilla-lazyload/#-demos&quot;&gt;demo di vanilla-lazyload&lt;/a&gt;, come la &lt;a href=&quot;https://verlok.github.io/vanilla-lazyload/demos/image_basic.html&quot;&gt;demo del caso base&lt;/a&gt;, limitando o disattivando la velocità di connessione nei developer tools del tuo browser.&lt;/p&gt;
&lt;h3 id=&quot;2-callback-avanzate-o-classi-css&quot; tabindex=&quot;-1&quot;&gt;2. Callback avanzate o classi CSS &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/#2-callback-avanzate-o-classi-css&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Il lazy loading gestito da JavaScript fornisce callback e classi CSS per vari eventi (inizio caricamento, fine caricamento, errore, ingresso nella viewport, uscita dalla viewport, ecc.), consentendo di monitorare il processo e creare effetti visivi avanzati.&lt;/p&gt;
&lt;p&gt;Queste callback e classi CSS possono essere molto utili per creare effetti visivi sulla pagina.&lt;/p&gt;
&lt;p&gt;Scopri di più su callback e classi nelle &lt;a href=&quot;https://verlok.github.io/vanilla-lazyload/#-api&quot;&gt;API di vanilla-lazyload&lt;/a&gt; / &lt;a href=&quot;https://verlok.github.io/vanilla-lazyload/#options&quot;&gt;opzioni&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;3-ottimizzare-le-performance-web-nello-specifico-il-largest-contentful-paint&quot; tabindex=&quot;-1&quot;&gt;3. Ottimizzare le performance web, nello specifico il Largest Contentful Paint &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/#3-ottimizzare-le-performance-web-nello-specifico-il-largest-contentful-paint&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Il lazy loading guidato da JavaScript offre un maggiore controllo su quali immagini vengono scaricate, aiutando a ottimizzare il Largest Contentful Paint (LCP).&lt;/p&gt;
&lt;p&gt;Con il lazy loading nativo, non hai il controllo su quali immagini vengono scaricate dal browser.&lt;/p&gt;
&lt;p&gt;Il caso d&#39;uso:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;alcune immagini sono sotto la piega ma non molto lontane&lt;/li&gt;
&lt;li&gt;alcune immagini compaiono appena nella parte visibile della pagina&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Il lazy loading nativo inizierebbe a scaricare queste immagini, che condividerebbero la larghezza di banda con il download dell&#39;immagine LCP, mentre vorresti scaricare quest&#39;ultima con la massima priorità.&lt;/p&gt;
&lt;p&gt;Il lazy loading gestito da JavaScript come vanilla-lazyload fornisce &lt;a href=&quot;https://verlok.github.io/vanilla-lazyload/#-api&quot;&gt;API&lt;/a&gt; e &lt;a href=&quot;https://verlok.github.io/vanilla-lazyload/#options&quot;&gt;opzioni&lt;/a&gt; per controllare con precisione quanto debbano essere distanti dalla viewport le immagini prima di iniziare a scaricarle.&lt;/p&gt;
&lt;h3 id=&quot;4-lazy-loading-di-altre-risorse&quot; tabindex=&quot;-1&quot;&gt;4. Lazy loading di altre risorse &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/#4-lazy-loading-di-altre-risorse&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Per effettuare il lazy loading di immagini di sfondo, video, SVG animati e altro, è ancora necessaria una libreria JavaScript come &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;scopri-di-piu&quot; tabindex=&quot;-1&quot;&gt;Scopri di più &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/do-we-still-need-lazy-loading-libraries-data-src/#scopri-di-piu&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Consulta la &lt;a href=&quot;https://verlok.github.io/vanilla-lazyload/&quot;&gt;documentazione di vanilla-lazyload&lt;/a&gt; o il mio post sul blog &lt;a href=&quot;https://andreaverlicchi.eu/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/&quot;&gt;lazy load delle immagini responsive nel 2020&lt;/a&gt;.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Talk: Velocizzare il web con le immagini responsive - LazyLoad Conference 2022</title>
		<link href="https://andreaverlicchi.eu/it/blog/lazyload-conference-talk-automating-responsive-images-automator/"/>
		<updated>2022-06-24T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/lazyload-conference-talk-automating-responsive-images-automator/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/-3gSKqUCg4-648.webp 648w, https://andreaverlicchi.eu/img/-3gSKqUCg4-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/-3gSKqUCg4-648.png 648w, https://andreaverlicchi.eu/img/-3gSKqUCg4-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi seduto nel suo soggiorno, durante il talk&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/-3gSKqUCg4-648.png&quot; width=&quot;1296&quot; height=&quot;728&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Questo è un fermo immagine del video, prima di entrare nelle parti tecniche&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Il 24 giugno 2022 ho parlato di &lt;strong&gt;ottimizzazione delle immagini responsive 4.0&lt;/strong&gt; alla conferenza &lt;a href=&quot;https://webdirections.org/lazyload/&quot;&gt;LazyLoad 2022&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Il talk spiega come migliorare le prestazioni del proprio sito web automatizzando le immagini responsive con un approccio basato sui dati. Ecco il video dell&#39;intervento.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/vuWH34f6uds?si=Za5a4gWUefluQ7-B&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Lo strumento menzionato nel talk è &lt;a href=&quot;https://github.com/verlok/responsive-images-automator&quot;&gt;responsive-images-automator&lt;/a&gt;.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Talk: Ottimizzazione delle immagini 4.0, automatizza il tuo lavoro con un approccio incentrato sull&#39;utente - CSS Day 2022</title>
		<link href="https://andreaverlicchi.eu/it/blog/css-day-2022-talk-automating-responsive-images-automator-ottimizzazione-immagini-4-0/"/>
		<updated>2022-04-01T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/css-day-2022-talk-automating-responsive-images-automator-ottimizzazione-immagini-4-0/</id>
		<content type="html">&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/1r7VhO8cDn-648.webp 648w, https://andreaverlicchi.eu/img/1r7VhO8cDn-1296.webp 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;source type=&quot;image/png&quot; srcset=&quot;https://andreaverlicchi.eu/img/1r7VhO8cDn-648.png 648w, https://andreaverlicchi.eu/img/1r7VhO8cDn-1296.png 1296w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Andrea Verlicchi sul palco del CSS Day 2022, Faenza, 1 aprile 2022&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/1r7VhO8cDn-648.png&quot; width=&quot;1296&quot; height=&quot;726&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Io sul palco del CSS Day 2022, Faenza&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Il 1° aprile 2022 ho parlato di &lt;strong&gt;ottimizzazione delle immagini responsive 4.0&lt;/strong&gt; alla conferenza &lt;a href=&quot;https://2022.cssday.it&quot;&gt;CSS Day 2022&lt;/a&gt; a Faenza. Questo talk affronta il tema di come diventare più produttivi automatizzando la gestione delle immagini responsive. Ecco il video del mio intervento.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/8D4skk17BGI?si=lSA2B2PT_dEfXY-l&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen=&quot;&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 9&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Lo strumento di cui ho parlato nel talk è &lt;a href=&quot;https://github.com/verlok/responsive-images-automator&quot;&gt;responsive-images-automator&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Il talk è stato valutato molto positivamente! &lt;a href=&quot;https://joind.in/event/cssday-2022/-ottimizzazione-immagini-40-a-data-driven--test-driven-approach&quot;&gt;Leggi i feedback su joind.in&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Trovi di seguito le slide dell&#39;intervento.&lt;/p&gt;
&lt;iframe loading=&quot;lazy&quot; src=&quot;https://www.slideshare.net/slideshow/embed_code/key/f0UQZznjoJ5Yvs?hostedIn=slideshare&amp;page=upload&quot; width=&quot;100%&quot; height=&quot;autp&quot; frameborder=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; style=&quot;width: 100%; height: auto; aspect-ratio: 16 / 11&quot;&gt;&lt;/iframe&gt;
</content>
	</entry>
	
	<entry>
		<title>Come integrare git nel Terminale (shell) di Mac OS</title>
		<link href="https://andreaverlicchi.eu/it/blog/how-integrate-git-autocomplete-mac-shell-terminal-bash-zsh/"/>
		<updated>2022-03-11T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/how-integrate-git-autocomplete-mac-shell-terminal-bash-zsh/</id>
		<content type="html">&lt;p&gt;Ora che &lt;code&gt;zsh&lt;/code&gt; è la shell predefinita sul terminale di Mac OS, potresti voler configurare il tuo nuovo Mac o il terminale di VS Code per avere un&#39;integrazione intelligente con &lt;code&gt;git&lt;/code&gt;, simile a &lt;a href=&quot;https://gitforwindows.org/&quot;&gt;git bash&lt;/a&gt; per Windows.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/fTQn3en4qR-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;App Terminale Mac OS X | blog-11ty git:(main) * git status | On branch main | Your branch is ahead of &#39;origin/main&#39; by 1 commit. (use &amp;quot;git push&amp;quot; to publish your local commits) | Changes not staged for commit: | (use &amp;quot;git add ‹file&gt;...&amp;quot; to update what will be committed) | (use &amp;quot;git restore ‹file&gt;...&amp;quot; to discard changes in working directory) | modified: content/blog/how-integrate-git-autocomplete-mac-shell-terminal-bash-zsh/index.md | no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/fTQn3en4qR-648.png&quot; width=&quot;648&quot; height=&quot;403&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Terminale Mac OS con integrazione git&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Dopo aver cercato in giro per un po&#39; e aver trovato strumenti per l&#39;integrazione con &lt;code&gt;bash&lt;/code&gt;, ho finalmente trovato &lt;a href=&quot;https://git-scm.com/book/en/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Zsh&quot;&gt;questo articolo&lt;/a&gt; che spiega come integrare &lt;code&gt;git&lt;/code&gt; con &lt;code&gt;zsh&lt;/code&gt; nel Terminale (o shell) di Mac OS.&lt;/p&gt;
&lt;p&gt;Poiché &lt;code&gt;zsh&lt;/code&gt; viene fornito con un framework per ottenere informazioni dai sistemi di controllo versione, chiamato &lt;a href=&quot;http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Version-Control-Information&quot;&gt;&lt;code&gt;vcs_info&lt;/code&gt;&lt;/a&gt;, puoi includere il nome del branch nel prompt sul lato destro aggiungendo queste righe al tuo file &lt;code&gt;~/.zshrc&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-dot&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-dot&quot;&gt;&lt;span class=&quot;token node&quot;&gt;autoload&lt;/span&gt; -Uz &lt;span class=&quot;token node&quot;&gt;vcs_info&lt;/span&gt;
&lt;span class=&quot;token node&quot;&gt;precmd_vcs_info&lt;/span&gt;() &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token node&quot;&gt;vcs_info&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token node&quot;&gt;precmd_functions&lt;/span&gt;+&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;( &lt;span class=&quot;token node&quot;&gt;precmd_vcs_info&lt;/span&gt; )
&lt;span class=&quot;token node&quot;&gt;setopt&lt;/span&gt; &lt;span class=&quot;token node&quot;&gt;prompt_subst&lt;/span&gt;
&lt;span class=&quot;token attr-name&quot;&gt;RPROMPT&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&#39;$&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token node&quot;&gt;vcs_info_msg_0_&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&#39;
&lt;span class=&quot;token comment&quot;&gt;# PROMPT=&#39;${vcs_info_msg_0_}%# &#39;&lt;/span&gt;
&lt;span class=&quot;token node&quot;&gt;zstyle&lt;/span&gt; &#39;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token node&quot;&gt;vcs_info&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token node&quot;&gt;git&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;*&#39; &lt;span class=&quot;token node&quot;&gt;formats&lt;/span&gt; &#39;%&lt;span class=&quot;token node&quot;&gt;b&lt;/span&gt;&#39;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Zsh è così potente che esistono interi framework dedicati a migliorarlo. Uno di questi si chiama &lt;a href=&quot;https://github.com/robbyrussell/oh-my-zsh&quot;&gt;&lt;code&gt;oh-my-zsh&lt;/code&gt;&lt;/a&gt;. Il sistema di plugin di &lt;code&gt;oh-my-zsh&lt;/code&gt; offre un potente autocompletamento (tab-completion) per git e dispone di una varietà di &amp;quot;temi&amp;quot; per il prompt, molti dei quali mostrano i dati del controllo versione.&lt;/p&gt;
&lt;p&gt;Puoi installare &lt;code&gt;oh-my-zsh&lt;/code&gt; eseguendo il seguente comando:&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;sh&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;curl&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh&lt;span class=&quot;token variable&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Goditi il tuo nuovo terminale &lt;code&gt;zsh&lt;/code&gt; integrato con i comandi &lt;code&gt;git&lt;/code&gt;!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Una tecnica elegante per il lazy loading delle immagini in Swiper e la creazione lazy delle istanze di Swiper</title>
		<link href="https://andreaverlicchi.eu/it/blog/lazyload-swiper-images-instances/"/>
		<updated>2021-10-27T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/lazyload-swiper-images-instances/</id>
		<content type="html">&lt;p&gt;Immagina di avere più caroselli in una pagina, ognuno contenente più immagini, e di voler scaricare solo le immagini che si trovano all&#39;interno della porzione visibile della pagina, magari risparmiando tempo di CPU creando le istanze del carosello in modalità lazy. Credo di aver trovato una tecnica valida ed elegante per farlo.&lt;/p&gt;
&lt;p&gt;La tecnica seguente riguarda il lazy loading delle immagini all&#39;interno di un&#39;istanza di &lt;a href=&quot;https://swiperjs.com/&quot;&gt;Swiper JS&lt;/a&gt; e la creazione differita (lazy) delle istanze di Swiper below-the-fold, utilizzando Swiper insieme a &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Il codice HTML del primo carosello imposta un paio di immagini da caricare immediatamente (eager) in modo che i browser diano priorità al loro scaricamento, lasciando tutto il resto al lazy loading.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper swiper--eager&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-wrapper&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Immagini caricate immediatamente (eager) --&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-slide&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=S01E01&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/440x560?text=S01E01 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-slide&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=S01E02&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/440x560?text=S01E02 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Immagini caricate in lazy loading --&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-slide&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=S01E03&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/440x560?text=S01E03 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-slide&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=S01E04&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/440x560?text=S01E04 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-slide&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=S01E05&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/440x560?text=S01E05 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-button-prev&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-button-next&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A partire dal secondo carosello, tutte le immagini vengono caricate in modalità lazy.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper swiper--lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiperLazy1&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-wrapper&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Tutte le immagini caricate in lazy loading --&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-slide&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=S02E01&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/440x560?text=S02E01 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-slide&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=S02E02&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/440x560?text=S02E02 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-slide&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=S02E03&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/440x560?text=S02E03 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-slide&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=S02E04&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/440x560?text=S02E04 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-slide&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=S02E05&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/440x560?text=S02E05 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
				&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-button-prev&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;swiper-button-next&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ecco il codice JavaScript che compie la magia.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; swiperOptions &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;slidesPerView&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;auto&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;navigation&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token literal-property property&quot;&gt;nextEl&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;.swiper-button-next&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;token literal-property property&quot;&gt;prevEl&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;.swiper-button-prev&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token comment&quot;&gt;// Carica in modalità lazy le immagini di Swiper dopo l&#39;inizializzazione di Swiper&lt;/span&gt;
		&lt;span class=&quot;token function-variable function&quot;&gt;afterInit&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;swiper&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LazyLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
				&lt;span class=&quot;token literal-property property&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; swiper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;el&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
				&lt;span class=&quot;token literal-property property&quot;&gt;cancel_on_exit&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Inizializza subito il primo swiper&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; eagerSwiper &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Swiper&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;.swiper--eager&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; swiperOptions&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Inizializza tutti gli altri swiper non appena entrano nel viewport&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LazyLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;elements_selector&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;.swiper--lazy&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;unobserve_entered&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token function-variable function&quot;&gt;callback_enter&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;swiperElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Swiper&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;#&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; swiperElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; swiperOptions&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ho testato questa soluzione emulando una connessione &amp;quot;3G lento&amp;quot;, e ho apprezzato la cascata di chiamate di rete e il valore ottimale ottenuto per il Largest Contentful Paint.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://verlok.github.io/vanilla-lazyload/demos/swiper.html&quot;&gt;Provalo live qui&lt;/a&gt;.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>vanilla-lazyload vs lazysizes</title>
		<link href="https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/"/>
		<updated>2021-09-26T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/</id>
		<content type="html">&lt;p&gt;Come autore di vanilla-lazyload, non è la prima volta che mi viene posta questa domanda: &lt;q&gt;Quali sono le differenze tra vanilla-lazyload e lazysizes?&lt;/q&gt; Questo post è la risposta a tale domanda.&lt;/p&gt;
&lt;img alt=&quot;vanilla-lazyload vs lazysizes&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/tRjMg3L7n7-648.webp&quot; width=&quot;648&quot; height=&quot;432&quot;&gt;
&lt;h2 id=&quot;cosa-sono-vanilla-lazyload-e-lazysizes&quot; tabindex=&quot;-1&quot;&gt;Cosa sono vanilla-lazyload e lazysizes? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#cosa-sono-vanilla-lazyload-e-lazysizes&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/&quot;&gt;vanilla-lazyload&lt;/a&gt; e &lt;a href=&quot;https://github.com/afarkas/lazysizes/&quot;&gt;lazysizes&lt;/a&gt; sono due popolari librerie JavaScript per il &lt;a href=&quot;https://web.dev/lazy-loading/&quot;&gt;lazy-loading&lt;/a&gt; di immagini e altri elementi DOM, il che significa &lt;strong&gt;caricarli solo quando entrano nella porzione visibile della pagina web&lt;/strong&gt; (il viewport del browser), o poco prima.&lt;/p&gt;
&lt;p&gt;L&#39;uso di una di esse è fondamentale per migliorare il &lt;strong&gt;tempo di rendering&lt;/strong&gt; del tuo sito web, posticipando il caricamento di tutti i contenuti non critici a un momento successivo, al fine di ottenere migliori &lt;a href=&quot;https://web.dev/cwv&quot;&gt;Core Web Vitals&lt;/a&gt; e in particolare di ridurre il &lt;a href=&quot;https://web.dev/lcp&quot;&gt;Largest Contentful Paint&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Quali sono quindi le &lt;strong&gt;differenze tra vanilla-lazyload e lazysizes&lt;/strong&gt;? Di seguito viene riportato un confronto dettagliato tra le due librerie.&lt;/p&gt;
&lt;h2 id=&quot;confronto-tra-vanilla-lazyload-e-lazysizes&quot; tabindex=&quot;-1&quot;&gt;Confronto tra vanilla-lazyload e lazysizes &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#confronto-tra-vanilla-lazyload-e-lazysizes&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Trovi le caratteristiche principali di vanilla-lazyload a confronto con quelle di lazysizes nella tabella seguente.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Caratteristica&lt;/th&gt;
&lt;th&gt;vanilla-lazyload&lt;/th&gt;
&lt;th&gt;lazysizes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;È leggera (fonte: &lt;a href=&quot;https://bundlephobia.com/&quot;&gt;bundlephobia&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;✔ (2.8 kB)&lt;/td&gt;
&lt;td&gt;✔ (3.4 kB)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;È estendibile&lt;/td&gt;
&lt;td&gt;✔ (via API)&lt;/td&gt;
&lt;td&gt;✔ (via plugin)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;È SEO friendly&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ottimizza le prestazioni annullando i download delle immagini già uscite dal viewport&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Riprova il caricamento se la connessione di rete cade e poi si ripristina&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Supporta l&#39;uso condizionale del lazy loading nativo&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Funziona con il tuo DOM, le tue classi e i tuoi attributi data-*&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Può caricare in modalità lazy immagini responsive&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;...e calcolare automaticamente il valore dell&#39;attributo sizes&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Può caricare in modalità lazy gli iframe&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Può caricare in modalità lazy i video&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Può caricare in modalità lazy immagini di sfondo&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Può eseguire codice in modalità lazy quando determinati elementi entrano nel viewport&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Può ripristinare il DOM allo stato originale&lt;/td&gt;
&lt;td&gt;✔&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;spiegazione-delle-righe-della-tabella&quot; tabindex=&quot;-1&quot;&gt;Spiegazione delle righe della tabella &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#spiegazione-delle-righe-della-tabella&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;e-estendibile&quot; tabindex=&quot;-1&quot;&gt;È estendibile &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#e-estendibile&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Sia vanilla-lazyload sia lazysizes sono estendibili, vedi le &lt;a href=&quot;https://www.github.com/verlok/vanilla-lazyload#-api&quot;&gt;API di vanilla-lazyload&lt;/a&gt; e i &lt;a href=&quot;https://github.com/aFarkas/lazysizes/tree/gh-pages/plugins&quot;&gt;plugin di lazysizes&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;e-seo-friendly&quot; tabindex=&quot;-1&quot;&gt;È SEO friendly &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#e-seo-friendly&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Entrambi gli script &lt;strong&gt;non nascondono le immagini o gli asset ai motori di ricerca&lt;/strong&gt;, indipendentemente dal pattern di markup utilizzato. I motori di ricerca non scorrono né interagiscono con il tuo sito. Questi script rilevano se lo user agent è in grado di scorrere la pagina e, in caso contrario, mostrano istantaneamente tutte le immagini.&lt;/p&gt;
&lt;h3 id=&quot;ottimizza-le-prestazioni-annullando-i-download-delle-immagini-gia-uscite-dal-viewport&quot; tabindex=&quot;-1&quot;&gt;Ottimizza le prestazioni annullando i download delle immagini già uscite dal viewport &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#ottimizza-le-prestazioni-annullando-i-download-delle-immagini-gia-uscite-dal-viewport&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Se i tuoi utenti mobili hanno connessioni lente e scorrono velocemente, vanilla-lazyload annulla il download delle immagini ancora in fase di caricamento ma che sono già uscite dal viewport. Se per qualche motivo preferisci evitare questo comportamento, questa funzione può essere disattivata.&lt;/p&gt;
&lt;h3 id=&quot;riprova-il-caricamento-se-la-connessione-di-rete-cade-e-poi-si-ripristina&quot; tabindex=&quot;-1&quot;&gt;Riprova il caricamento se la connessione di rete cade e poi si ripristina &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#riprova-il-caricamento-se-la-connessione-di-rete-cade-e-poi-si-ripristina&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Se i tuoi utenti da mobile hanno connessioni instabili e passano offline per poi tornare online, vanilla-lazyload riprova a scaricare le immagini che avevano generato un errore.&lt;/p&gt;
&lt;h3 id=&quot;supporta-l-uso-condizionale-del-lazy-loading-nativo&quot; tabindex=&quot;-1&quot;&gt;Supporta l&#39;uso condizionale del lazy-loading nativo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#supporta-l-uso-condizionale-del-lazy-loading-nativo&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Se i tuoi utenti utilizzano un browser che supporta il lazy-loading nativo e desideri utilizzarlo, con vanilla-lazyload puoi attivarlo in modo condizionale impostando l&#39;opzione &lt;code&gt;use_native&lt;/code&gt; a &lt;code&gt;true&lt;/code&gt;. Trovi qui &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload#mixed-native-and-js-based-lazy-loading&quot;&gt;maggiori informazioni&lt;/a&gt; e la &lt;a href=&quot;https://verlok.github.io/vanilla-lazyload/demos/native_lazyload_conditional.html&quot;&gt;demo del lazy-loading nativo condizionale&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;funziona-con-il-tuo-dom-le-tue-classi-e-i-tuoi-attributi-data&quot; tabindex=&quot;-1&quot;&gt;Funziona con il tuo DOM, le tue classi e i tuoi attributi data-* &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#funziona-con-il-tuo-dom-le-tue-classi-e-i-tuoi-attributi-data&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Entrambi gli script funzionano per impostazione predefinita con l&#39;attributo &lt;code&gt;data-src&lt;/code&gt; e la classe &lt;code&gt;lazy&lt;/code&gt; nel tuo DOM. Tuttavia, in vanilla-lazyload puoi modificarli (ad esempio in &lt;code&gt;data-origin&lt;/code&gt;), se desideri migrare da altri script di caricamento lazy a vanilla-lazyload senza dover cambiare il markup HTML.&lt;/p&gt;
&lt;h3 id=&quot;puo-caricare-in-modalita-lazy-le-immagini-responsive&quot; tabindex=&quot;-1&quot;&gt;Può caricare in modalità lazy le immagini responsive &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#puo-caricare-in-modalita-lazy-le-immagini-responsive&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Sia vanilla-lazyload sia lazysizes possono caricare in modalità lazy immagini responsive di ogni tipo, dal semplice tag &lt;code&gt;img&lt;/code&gt; al tag &lt;code&gt;picture&lt;/code&gt; con tag &lt;code&gt;source&lt;/code&gt; multipli.&lt;/p&gt;
&lt;p&gt;Per ulteriori informazioni, consulta l&#39;articolo &lt;a href=&quot;https://andreaverlicchi.eu/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/&quot;&gt;Lazy loading delle immagini responsive nel 2020&lt;/a&gt; scritto dal sottoscritto.&lt;/p&gt;
&lt;h3 id=&quot;e-calcolare-automaticamente-il-valore-dell-attributo-sizes&quot; tabindex=&quot;-1&quot;&gt;...e calcolare automaticamente il valore dell&#39;attributo &lt;code&gt;sizes&lt;/code&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#e-calcolare-automaticamente-il-valore-dell-attributo-sizes&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Lo script lazysizes ha una funzione che può risparmiarti la &amp;quot;fatica&amp;quot; di scrivere il valore dell&#39;attributo &lt;code&gt;sizes&lt;/code&gt; nel tuo markup HTML. Inserendo &lt;code&gt;data-sizes=&amp;quot;auto&amp;quot;&lt;/code&gt; nel markup delle tue immagini, la libreria calcola il valore tramite JavaScript basandosi sul tuo CSS.&lt;/p&gt;
&lt;p&gt;Questa funzionalità manca intenzionalmente in vanilla-lazyload. Per fare in modo che i browser visualizzino i contenuti del tuo sito il più velocemente possibile, dovrai &lt;strong&gt;combinare lazy loading ed eager loading&lt;/strong&gt; (eager è il contrario di lazy). La best practice in questo caso consiste nel caricare immediatamente (eager) le immagini above-the-fold e in modalità lazy quelle below-the-fold. Nelle immagini caricate subito (eager), dovrai comunque impostare un valore corretto per l&#39;attributo &lt;code&gt;sizes&lt;/code&gt;. Ciò significa che dovrai calcolare quel valore in ogni caso e, una volta fatto, che senso ha calcolarlo di nuovo tramite JavaScript? Puoi utilizzare lo stesso valore calcolato sia per le immagini eager sia per quelle lazy.&lt;/p&gt;
&lt;h3 id=&quot;puo-caricare-in-modalita-lazy-gli-iframe&quot; tabindex=&quot;-1&quot;&gt;Può caricare in modalità lazy gli iframe &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#puo-caricare-in-modalita-lazy-gli-iframe&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Sia vanilla-lazyload sia lazysizes possono caricare in modalità lazy il tag &lt;code&gt;iframe&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;puo-caricare-in-modalita-lazy-i-video&quot; tabindex=&quot;-1&quot;&gt;Può caricare in modalità lazy i video &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#puo-caricare-in-modalita-lazy-i-video&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Solo vanilla-lazyload può caricare in modalità lazy il tag &lt;code&gt;video&lt;/code&gt;, anche con tag &lt;code&gt;source&lt;/code&gt; multipli.&lt;/p&gt;
&lt;p&gt;Vedi la sezione &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload#lazy-video&quot;&gt;lazy video&lt;/a&gt; nella documentazione di vanilla-lazyload per maggiori dettagli.&lt;/p&gt;
&lt;h3 id=&quot;puo-caricare-in-modalita-lazy-le-immagini-di-sfondo&quot; tabindex=&quot;-1&quot;&gt;Può caricare in modalità lazy le immagini di sfondo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#puo-caricare-in-modalita-lazy-le-immagini-di-sfondo&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Solo vanilla-lazyload può caricare in modalità lazy le immagini di sfondo, comprese quelle multiple. Offre inoltre una modalità per supportare display HiDPI come Retina e Super Retina.&lt;/p&gt;
&lt;p&gt;Vedi la sezione &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload#lazy-background-image&quot;&gt;lazy background images&lt;/a&gt; nella documentazione di vanilla-lazyload per maggiori dettagli.&lt;/p&gt;
&lt;h3 id=&quot;puo-eseguire-codice-in-modalita-lazy-quando-determinati-elementi-entrano-nel-viewport&quot; tabindex=&quot;-1&quot;&gt;Può eseguire codice in modalità lazy quando determinati elementi entrano nel viewport &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#puo-eseguire-codice-in-modalita-lazy-quando-determinati-elementi-entrano-nel-viewport&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Solo con vanilla-lazyload puoi eseguire del codice quando determinati elementi entrano nella parte visibile della pagina.&lt;/p&gt;
&lt;p&gt;Vedi la sezione &lt;a href=&quot;https://www.github.com/verlok/vanilla-lazyload#lazy-functions&quot;&gt;lazy functions&lt;/a&gt; nella documentazione di vanilla-lazyload per saperne di più.&lt;/p&gt;
&lt;h3 id=&quot;puo-ripristinare-il-dom-allo-stato-originale&quot; tabindex=&quot;-1&quot;&gt;Può ripristinare il DOM allo stato originale &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#puo-ripristinare-il-dom-allo-stato-originale&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A volte è necessario ripulire il DOM prima di scaricarlo ed effettuare una navigazione fluida verso un&#39;altra pagina, ad esempio quando si utilizza TurboLinks.&lt;/p&gt;
&lt;p&gt;vanilla-lazyload ti consente di ripristinare tutto il DOM che ha manipolato al suo stato originale chiamando il metodo &lt;code&gt;restoreAll()&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/vanilla-lazyload-vs-lazysizes/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;vanilla-lazyload offre più funzionalità per il lazy-loading di immagini, immagini di sfondo, video e iframe; è ottimizzato per connessioni lente, riprova automaticamente a caricare le immagini dopo una disconnessione di rete, supporta il lazy loading nativo condizionale, può eseguire codice in modalità lazy e ripristinare il DOM allo stato originale.&lt;/p&gt;
&lt;p&gt;Dall&#39;altro lato, lazysizes è estendibile e offre la possibilità di calcolare automaticamente l&#39;attributo &lt;code&gt;sizes&lt;/code&gt; delle immagini, se preferisci non farlo manualmente.&lt;/p&gt;
&lt;p&gt;Link:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;Pagina GitHub di vanilla-lazyload&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/afarkas/lazysizes/&quot;&gt;Pagina GitHub di lazysizes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
	</entry>
	
	<entry>
		<title>Case study su Quicklink: pagine più veloci, aumento delle visualizzazioni</title>
		<link href="https://andreaverlicchi.eu/it/blog/quicklink-case-study-faster-pages-increased-page-views/"/>
		<updated>2021-06-18T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/quicklink-case-study-faster-pages-increased-page-views/</id>
		<content type="html">&lt;p&gt;&lt;a href=&quot;https://github.com/GoogleChromeLabs/quicklink&quot;&gt;QuickLink&lt;/a&gt; è una libreria leggera creata da Addy Osmani (Google) che esegue il prefetch delle pagine collegate alla pagina corrente non appena i link a tali pagine entrano nella porzione visibile della pagina (viewport).&lt;/p&gt;
&lt;img alt=&quot;Il logo di Quicklink&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/vt2DvehcqM-648.webp&quot; width=&quot;648&quot; height=&quot;243&quot;&gt;
&lt;p&gt;Abbiamo utilizzato Quicklink su alcuni dei nostri siti di e-commerce per migliorare i tempi di rendering delle pagine di dettaglio prodotto (PDP), ottenendo buoni risultati sia in termini di prestazioni sia per i KPI di business.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/ynap-tech/quicklink-case-study-faster-pages-increased-page-views-1e829dbaa10c&quot;&gt;Continua a leggere su Medium&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Un modo intelligente per servire immagini WebP ai browser moderni e JPG a Internet Explorer</title>
		<link href="https://andreaverlicchi.eu/it/blog/clever-way-serve-webp-modern-browsers-jpg-internet-explorer/"/>
		<updated>2020-11-29T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/clever-way-serve-webp-modern-browsers-jpg-internet-explorer/</id>
		<content type="html">&lt;p&gt;Prima che Safari iniziasse a supportare le immagini WebP, eravamo costretti a usare il tag &lt;code&gt;picture&lt;/code&gt; per servire le immagini WebP ai browser che le supportavano. Oggi tutti i browser moderni supportano il formato WebP, quindi c&#39;è probabilmente un modo intelligente per farlo usando un singolo tag: &lt;code&gt;img&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;come-facevamo-prima&quot; tabindex=&quot;-1&quot;&gt;Come facevamo prima &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/clever-way-serve-webp-modern-browsers-jpg-internet-explorer/#come-facevamo-prima&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il vecchio metodo consisteva nell&#39;utilizzare un tag &lt;code&gt;picture&lt;/code&gt; contenente il normale tag &lt;code&gt;img&lt;/code&gt; con gli attributi &lt;code&gt;src&lt;/code&gt; e &lt;code&gt;srcset&lt;/code&gt; per i browser che non supportavano il formato WebP, e un tag &lt;code&gt;source&lt;/code&gt; fratello — contrassegnato con &lt;code&gt;type=&amp;quot;image/webp&amp;quot;&lt;/code&gt; — contenente lo &lt;code&gt;srcset&lt;/code&gt; per i browser in grado di visualizzare il formato WebP.&lt;/p&gt;
&lt;p&gt;In poche parole, questo:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
        &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image/webp&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
            {url-standard}.webp 1x,
            {url-retina}.webp   2x
        &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
        &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Vecchio metodo&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;{url-standard}.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
            {url-standard}.jpg 1x,
            {url-retina}.jpg   2x
        &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;ma-ora-safari-e-piu-moderno&quot; tabindex=&quot;-1&quot;&gt;Ma ora Safari è più moderno &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/clever-way-serve-webp-modern-browsers-jpg-internet-explorer/#ma-ora-safari-e-piu-moderno&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ora che tutti i browser moderni supportano il formato WebP, possiamo presumere che tutti i browser che supportano l&#39;attributo &lt;code&gt;srcset&lt;/code&gt; supportino anche il WebP. Possiamo quindi eliminare il tag &lt;code&gt;picture&lt;/code&gt; e utilizzare un singolo tag &lt;code&gt;img&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In questo modo:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Nuovo metodo intelligente&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;{url-standard}.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
        {url-standard}.webp 1x,
        {url-retina}.webp   2x
    &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I browser legacy utilizzeranno come fallback l&#39;attributo &lt;code&gt;src&lt;/code&gt;, scaricando l&#39;immagine JPG. Semplice.&lt;/p&gt;
&lt;h2 id=&quot;vantaggi&quot; tabindex=&quot;-1&quot;&gt;Vantaggi &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/clever-way-serve-webp-modern-browsers-jpg-internet-explorer/#vantaggi&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il primo e più ovvio vantaggio è che è necessario scrivere e mantenere meno markup HTML.&lt;/p&gt;
&lt;p&gt;Un secondo vantaggio si potrebbe avere se si stesse utilizzando una CDN per immagini per servire automaticamente il formato corretto in base al browser che lo richiede. In tal caso, probabilmente si può fare a meno di questo servizio, risparmiando tempo e denaro.&lt;/p&gt;
&lt;h2 id=&quot;compatibilita&quot; tabindex=&quot;-1&quot;&gt;Compatibilità &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/clever-way-serve-webp-modern-browsers-jpg-internet-explorer/#compatibilita&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se devi supportare versioni di iOS precedenti alla 14, probabilmente ti converrà continuare a utilizzare il tag &lt;code&gt;picture&lt;/code&gt; per farlo. Questo dipende dal pubblico a cui ti rivolgi. Puoi scoprire di più sul tuo pubblico analizzando i dati di Google Analytics.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Come limitare la fedeltà delle immagini a 2x e risparmiare il 45% del peso sui telefoni cellulari di fascia alta</title>
		<link href="https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/"/>
		<updated>2020-11-11T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/</id>
		<content type="html">&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/KPZpoNl1-w-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Limitare la fedeltà delle immagini a 2x&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/KPZpoNl1-w-648.jpeg&quot; width=&quot;648&quot; height=&quot;432&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;p&gt;Con la diffusione di schermi ad altissima densità “super retina” nei dispositivi di fascia alta più recenti, limitare la fedeltà delle immagini a 2x porta a un notevole miglioramento nei tempi di rendering, senza alcuna perdita di qualità percepibile per gli utenti. Ecco una nuova best practice su come fare.&lt;/p&gt;
&lt;h2 id=&quot;immagini-e-densita-degli-schermi&quot; tabindex=&quot;-1&quot;&gt;Immagini e densità degli schermi &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/#immagini-e-densita-degli-schermi&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Nel giugno 2010, Apple ha introdotto il primo display Retina sull&#39;iPhone 4. &amp;quot;Retina&amp;quot; è solo un nome commerciale per descrivere uno schermo HiDPI, che ha il doppio dei pixel in orizzontale e in verticale (2x).&lt;/p&gt;
&lt;p&gt;Gli schermi HiDPI sono perfetti per il rendering di vettori come font e immagini SVG, ma quando si tratta di immagini bitmap, se non forniamo un&#39;immagine specifica per display HiDPI, la nostra immagine standard viene allungata (ingrandita) per coprire tutti i pixel aggiuntivi. E le immagini allungate non hanno un bell&#39;aspetto.&lt;/p&gt;
&lt;p&gt;Così, la prima cosa che abbiamo iniziato a fare è stata fornire sia un&#39;immagine standard sia un&#39;immagine ottimizzata per gli schermi Retina, utilizzando l&#39;attributo &lt;code&gt;srcset&lt;/code&gt; e il descrittore &lt;code&gt;x&lt;/code&gt;. In questo modo:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_1x.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_1x.jpg 1x, batman_2x.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Batman, Super-man and Wonder Woman&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;1280&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;720&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quel descrittore &lt;code&gt;x&lt;/code&gt; nell&#39;attributo &lt;code&gt;srcset&lt;/code&gt; serve ad associare le sorgenti alle densità dello schermo. &lt;code&gt;1x&lt;/code&gt; significa &amp;quot;questa è l&#39;immagine per schermi normali&amp;quot;, &lt;code&gt;2x&lt;/code&gt; significa &amp;quot;questa è l&#39;immagine per display HiDPI / Retina&amp;quot;. A seconda dello schermo del dispositivo, i browser sceglieranno la sorgente corrispondente.&lt;/p&gt;
&lt;h2 id=&quot;immagini-responsive&quot; tabindex=&quot;-1&quot;&gt;Immagini responsive &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/#immagini-responsive&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Quella delle &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images&quot;&gt;immagini responsive&lt;/a&gt; è una specifica HTML che ci consente di servire la dimensione corretta dell&#39;immagine agli utenti, a seconda dello spazio che l&#39;immagine occupa sul loro schermo e tenendo conto del pixel ratio del dispositivo.&lt;/p&gt;
&lt;p&gt;Il modo più semplice per scrivere il codice per le immagini responsive è elencare tutte le dimensioni d&#39;immagine disponibili in un attributo &lt;code&gt;srcset&lt;/code&gt;, utilizzando il descrittore &lt;code&gt;w&lt;/code&gt;, e indicare al browser quanto è grande la nostra immagine tramite l&#39;attributo &lt;code&gt;sizes&lt;/code&gt;. I browser faranno i calcoli e scaricheranno l&#39;immagine più appropriata.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_1280w.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_1280w.jpg 1280w, batman_1024w.jpg 1024w, batman_768w.jpg 768w&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Batman, Super-man and Wonder Woman&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;100vw&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Inoltre, se la dimensione delle immagini cambia a seconda delle media query, possiamo aggiungere le stesse media query nell&#39;attributo &lt;code&gt;sizes&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_1280w.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
		batman_1440w.jpg 1440w,
		batman_1280w.jpg 1280w,
		batman_1024w.jpg 1024w,
		batman_768w.jpg   768w
	&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Batman, Super-man and Wonder Woman&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: 640px) 50vw, 100vw&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Se ti senti confuso, ti consiglio di leggere &lt;a href=&quot;https://ericportis.com/posts/2014/srcset-sizes/&quot;&gt;Srcset and Sizes di Eric Portis&lt;/a&gt;. Quell&#39;articolo mi ha illuminato la strada quando ho iniziato a sperimentare con le immagini responsive.&lt;/p&gt;
&lt;h2 id=&quot;dispositivi-con-schermi-3x&quot; tabindex=&quot;-1&quot;&gt;Dispositivi con schermi 3x &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/#dispositivi-con-schermi-3x&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Al momento della scrittura di questo articolo, ci sono diversi dispositivi di fascia alta, sia di Apple che di Google, che montano uno schermo HiDPI con una densità di pixel pari a 3x o superiore. Apple li chiama display Super Retina, Google li chiama display FHD+.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/1EK9ztJTx7-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Apple iPhone 12 Mini, Apple iPhone X, Apple iPhone XS, Apple iPhone 11 Pro, Google Pixel 3, Google Pixel 4, Google Pixel 5, Apple iPhone 12, Apple iPhone 12 Pro&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/1EK9ztJTx7-648.jpeg&quot; width=&quot;648&quot; height=&quot;529&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Dispositivi con display super HiDPI&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Apple ha lanciato il suo primo display Super Retina con l&#39;iPhone X; lo stesso tipo di display è montato su iPhone XS / Max, iPhone 11 Pro / 11 Pro Max e su tutti i telefoni della linea iPhone 12, compreso il 12 Mini.&lt;/p&gt;
&lt;p&gt;I telefoni Google Pixel hanno display FHD+ con densità di pixel 3x, e display QHD+ con una densità di 3.5x sul Pixel 4 XL.&lt;/p&gt;
&lt;h2 id=&quot;limitare-la-fedelta-delle-immagini&quot; tabindex=&quot;-1&quot;&gt;Limitare la fedeltà delle immagini &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/#limitare-la-fedelta-delle-immagini&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Secondo l&#39;analisi effettuata su una &lt;a href=&quot;https://blog.twitter.com/engineering/en_us/topics/infrastructure/2019/capping-image-fidelity-on-ultra-high-resolution-devices.html&quot;&gt;modifica all&#39;app mobile di Twitter&lt;/a&gt;, limitare la fedeltà dell&#39;immagine a 2x porta a un notevole miglioramento dei tempi di rendering e a nessuna perdita di qualità percepibile dagli utenti.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Le immagini nelle timeline sui dispositivi a risoluzione ultra-elevata ora si caricano circa il 33% più velocemente consumando un terzo di dati in meno, e senza alcuna variazione visibile della qualità.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Il problema con la gestione delle immagini responsive tramite il tag &lt;code&gt;img&lt;/code&gt;, come abbiamo visto sopra, è che non c&#39;è modo di impedire ai browser di scaricare l&#39;immagine 3x. Il motivo è che per determinar quale immagine scaricare dallo &lt;code&gt;srcset&lt;/code&gt;, effettuano questo calcolo:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;larghezza dell&#39;immagine sullo schermo × densità di pixel del dispositivo = larghezza dell&#39;immagine da scaricare
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ad esempio, se un&#39;immagine deve essere visualizzata con una larghezza di &lt;code&gt;300px&lt;/code&gt; su un iPhone 12, i browser eseguiranno il seguente calcolo:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;300 × 3 = 900
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;E scaricherebbero l&#39;immagine larga 900 pixel. Quello che vogliamo fare noi è limitare la fedeltà a 2x in modo che scarichi invece l&#39;immagine larga 600 pixel.&lt;/p&gt;
&lt;p&gt;L&#39;unico modo per farlo sul web è utilizzare il tag &lt;code&gt;picture&lt;/code&gt; in questo modo:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Tablet in modalità landscape / computer --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ####px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg 1x, batman_###w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Tablet in modalità portrait / smartphone in modalità landscape --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ###px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Smartphone più grandi --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ###px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Smartphone più piccoli --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Batman Super-man e Wonder&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nota: ho sostituito i numeri reali con un segnaposto &lt;code&gt;###&lt;/code&gt; perché quei valori non sono rilevanti per questa spiegazione.&lt;/p&gt;
&lt;p&gt;Nota che:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;nelle media query degli smartphone descriviamo solo l&#39;immagine &lt;code&gt;2x&lt;/code&gt;, poiché oggi tutti gli smartphone montano un display retina&lt;/li&gt;
&lt;li&gt;nelle media query per tablet in modalità landscape (orizzontale) e computer, dovremmo descrivere sia le immagini &lt;code&gt;1x&lt;/code&gt; sia quelle &lt;code&gt;2x&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;l&#39;attributo &lt;code&gt;src&lt;/code&gt; sul tag &lt;code&gt;img&lt;/code&gt; è obbligatorio, ma verrà utilizzato solo dai browser legacy, incluso IE 11&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ridurre-opzionalmente-la-complessita-sulle-media-query-di-tablet-e-computer&quot; tabindex=&quot;-1&quot;&gt;Ridurre opzionalmente la complessità sulle media query di tablet e computer &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/#ridurre-opzionalmente-la-complessita-sulle-media-query-di-tablet-e-computer&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se il tuo layout richiede più di una media query per tablet e computer, dovresti considerare l&#39;uso dell&#39;attributo &lt;code&gt;srcset&lt;/code&gt; con il descrittore &lt;code&gt;w&lt;/code&gt; e l&#39;attributo &lt;code&gt;sizes&lt;/code&gt;, ottenendo questo:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Tablet in modalità landscape / computer --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ###px) &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ###px) 33vw, 50vw&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
            batman_####w.jpg ####w,
            batman_####w.jpg ####w,
            batman_###w.jpg   ###w
        &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Tablet in modalità portrait / smartphone in modalità landscape --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ###px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Smartphone più grandi --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ###px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Smartphone più piccoli --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Batman Super-man e Wonder&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In questo modo, a partire dalla media query per tablet landscape e computer, non avrai bisogno di aggiungere altri tag &lt;code&gt;source&lt;/code&gt;, poiché non c&#39;è necessità di limitare la qualità dell&#39;immagine sui computer. Il tag &lt;code&gt;source&lt;/code&gt; più in alto si occuperà di tutto.&lt;/p&gt;
&lt;h2 id=&quot;e-un-sacco-di-markup-per-una-sola-immagine-dirai&quot; tabindex=&quot;-1&quot;&gt;“È un sacco di markup per una sola immagine”, dirai? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/#e-un-sacco-di-markup-per-una-sola-immagine-dirai&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se utilizzi immagini responsive, probabilmente hai già tag &lt;code&gt;img&lt;/code&gt; di dimensioni considerevoli, ognuno dei quali elenca un set di URL di immagini nell&#39;attributo &lt;code&gt;srcset&lt;/code&gt; e un set di media query e dimensioni nell&#39;attributo &lt;code&gt;sizes&lt;/code&gt;. Il codice mostrato sopra può essere leggermente più esteso, ma non in modo significativo.&lt;/p&gt;
&lt;p&gt;Detto questo, strumenti come GZip e Brotli — che funzionano nativamente nella maggior parte dei server applicativi e delle CDN — svolgono un lavoro eccellente nel comprimere i caratteri ripetuti nel markup, e ci sono molti caratteri ripetuti in questi tag di immagine.&lt;/p&gt;
&lt;p&gt;Ho fatto un test e ho scoperto che un file HTML contenente 54 immagini pesa 37 kb non compresso, ma solo 530 byte una volta compresso con GZip. Se si confronta questo dato con un &lt;strong&gt;risparmio del 45% sui dati&lt;/strong&gt; per le immagini scaricate, si tratta sicuramente di un ottimo compromesso.&lt;/p&gt;
&lt;h2 id=&quot;risultato-immagini-piu-leggere-del-45&quot; tabindex=&quot;-1&quot;&gt;Risultato: immagini più leggere del 45% &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/#risultato-immagini-piu-leggere-del-45&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;L&#39;utilizzo di questa tecnica sulla pagina dell&#39;elenco dei prodotti di uno dei siti che gestiamo ha portato a una &lt;strong&gt;riduzione del peso delle immagini del 45%&lt;/strong&gt;. Il peso delle immagini su un iPhone 11 Pro era di 1.7 MB prima ed è di soli 949 kB dopo la limitazione.&lt;/p&gt;
&lt;figure&gt;
	&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/RhbzfQii2W-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Nome w476.jpg, Dimensione 185kb vs Nome w360jpg, Dimensione 102kb, ecc.&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/RhbzfQii2W-648.jpeg&quot; width=&quot;648&quot; height=&quot;353&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Peso delle immagini prima (a sinistra) e dopo la limitazione (a destra)&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;div class=&quot;videoWrapper&quot;&gt;
    &lt;iframe loading=&quot;lazy&quot; width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/c2frAgQ_8lQ&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;h2 id=&quot;demo&quot; tabindex=&quot;-1&quot;&gt;Demo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/#demo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ho creato una &lt;a href=&quot;https://github.com/verlok/cap-image-fidelity-to-2x&quot;&gt;repository su GitHub&lt;/a&gt; e un &lt;a href=&quot;https://codepen.io/verlok/pen/wvWRgEG&quot;&gt;Codepen&lt;/a&gt;. Sentiti libero di provarli e di farne un fork.&lt;/p&gt;
&lt;p&gt;Singola immagine con fedeltà limitata a 2x:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/verlok/cap-image-fidelity-to-2x&quot;&gt;repository su GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://verlok.github.io/cap-image-fidelity-to-2x/&quot;&gt;Live qui&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://codepen.io/verlok/pen/wvWRgEG&quot;&gt;Codepen&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;O prova &lt;a href=&quot;https://faulty-driving.surge.sh/&quot;&gt;la pagina mostrata nel video sopra&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;🌟 &lt;a href=&quot;https://verlok.github.io/cap-image-fidelity-to-2x/&quot;&gt;Apri la demo live&lt;/a&gt; 💻&lt;/p&gt;
&lt;h2 id=&quot;psst-puoi-ancora-caricare-le-immagini-in-modalita-lazy&quot; tabindex=&quot;-1&quot;&gt;Psst! Puoi ancora caricare le immagini in modalità lazy &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/#psst-puoi-ancora-caricare-le-immagini-in-modalita-lazy&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Una delle migliori pratiche per ridurre al minimo il &lt;a href=&quot;https://web.dev/lcp/&quot;&gt;Largest Contentful Paint (LCP)&lt;/a&gt; del tuo sito consiste nel caricare immediatamente (eager) le immagini above-the-fold e in modalità lazy quelle below-the-fold. Puoi farlo utilizzando &lt;code&gt;data-src&lt;/code&gt;, &lt;code&gt;data-srcset&lt;/code&gt;, &lt;code&gt;data-sizes&lt;/code&gt; al posto di &lt;code&gt;src&lt;/code&gt;, &lt;code&gt;srcset&lt;/code&gt;, &lt;code&gt;sizes&lt;/code&gt; sia nei tag &lt;code&gt;img&lt;/code&gt; sia in quelli &lt;code&gt;source&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Tablet in modalità landscape / computer --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ###px) &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ###px) 33vw, 50vw&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
            batman_####w.jpg ####w,
            batman_####w.jpg ####w,
            batman_###w.jpg   ###w
        &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Tablet in modalità portrait / smartphone in modalità landscape --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ###px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Smartphone più grandi --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: ###px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Smartphone più piccoli --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;batman_###w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Batman Super-man e Wonder&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Maggiori informazioni sul &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp&quot;&gt;lazy loading delle immagini responsive nel 2020&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;per-concludere&quot; tabindex=&quot;-1&quot;&gt;Per concludere &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/capping-image-fidelity-2x-minimize-loading-time/#per-concludere&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Nel web design con immagini responsive, limitare la fedeltà delle immagini su dispositivi super HiDPI è una best practice relativamente nuova, dovuta al numero sempre crescente di smartphone dotati di schermi super HiDPI.&lt;/p&gt;
&lt;p&gt;Limitare la fedeltà dell&#39;immagine migliorerà la velocità di rendering del tuo sito, l&#39;esperienza dei tuoi utenti e la metrica &lt;a href=&quot;https://web.dev/lcp/&quot;&gt;Largest Contentful Paint&lt;/a&gt; delle tue pagine.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Come ottimizzare il CLS quando si caricano altri contenuti in modo asincrono</title>
		<link href="https://andreaverlicchi.eu/it/blog/optimise-cls-loading-more-content-pagination/"/>
		<updated>2020-08-31T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/optimise-cls-loading-more-content-pagination/</id>
		<content type="html">&lt;p&gt;Il Cumulative Layout Shift (CLS) è un&#39;importante metrica incentrata sull&#39;utente per misurare la stabilità visiva, poiché aiuta a quantificare la frequenza con cui gli utenti riscontrano spostamenti imprevisti del layout — un CLS basso aiuta a garantire che l&#39;esperienza sulla pagina sia piacevole.&lt;/p&gt;
&lt;img alt=&quot;Un sito web che mostra 4 immagini e un pulsante Carica altro&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/Hpjjdm7Lao-648.webp&quot; width=&quot;648&quot; height=&quot;430&quot;&gt;
&lt;p&gt;Quello che forse non sai è che:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Il CLS viene misurato continuamente&lt;/strong&gt;. Di fatto, il suo valore viene aggiornato anche mentre gli utenti scorrono la pagina, se lo scorrimento genera movimenti del layout&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;La misurazione del CLS viene sospesa per 500 ms&lt;/strong&gt; ogni volta che si verifica un&#39;interazione dell&#39;utente, come un clic o un evento da tastiera&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In parole povere, il Cumulative Layout Shift misura ogni movimento imprevisto del layout che si verifica mentre gli utenti interagiscono con la pagina, incluso quando scorrono verso il basso.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Quando carichiamo altri contenuti nelle nostre pagine, la causa più comune di CLS è il footer della pagina che diventa visibile per un momento, per poi essere spinto nuovamente below-the-fold dal nuovo contenuto aggiunto dinamicamente.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Quindi, come possiamo evitare che il CLS aumenti quando dobbiamo caricare dinamicamente nuovi contenuti, ad esempio per caricare un&#39;intera nuova pagina di prodotti?&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/ynap-tech/how-to-optimize-for-cls-when-having-to-load-more-content-3f60f0cf561c&quot;&gt;Continua a leggere su Medium&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Lazy loading delle immagini responsive nel 2020</title>
		<link href="https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/"/>
		<updated>2020-05-24T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/</id>
		<content type="html">&lt;p&gt;Vuoi migliorare le prestazioni del tuo sito web? Puoi farlo usando le &lt;strong&gt;immagini responsive&lt;/strong&gt; e il &lt;strong&gt;lazy loading&lt;/strong&gt;! In questo articolo troverai il codice &lt;strong&gt;HTML, JavaScript e CSS&lt;/strong&gt; per il lazy-loading delle immagini responsive, per fare in modo che i browser utilizzino &lt;strong&gt;formati di immagine moderni&lt;/strong&gt; come &lt;strong&gt;WebP&lt;/strong&gt; e &lt;strong&gt;Jpeg2000&lt;/strong&gt;, e per abilitare il &lt;strong&gt;lazy-loading nativo&lt;/strong&gt; dove supportato.&lt;/p&gt;
&lt;img alt=&quot;Lazy Load delle immagini responsive nel 2020&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/gzU4RsZnz1-648.webp&quot; width=&quot;648&quot; height=&quot;432&quot;&gt;
&lt;h2 id=&quot;definizioni&quot; tabindex=&quot;-1&quot;&gt;Definizioni &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#definizioni&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Le &lt;strong&gt;immagini responsive&lt;/strong&gt; sono tag &lt;code&gt;img&lt;/code&gt; che scaricano la sorgente d&#39;immagine corretta a seconda del design e del dispositivo dell&#39;utente. Puoi fornire informazioni sul layout nell&#39;attributo &lt;code&gt;sizes&lt;/code&gt; e un elenco di sorgenti d&#39;immagine nell&#39;attributo &lt;code&gt;srcset&lt;/code&gt;. Puoi anche utilizzare le media query racchiudendo il tag &lt;code&gt;img&lt;/code&gt; in un tag &lt;code&gt;picture&lt;/code&gt;. Maggiori informazioni sulle &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images&quot;&gt;immagini responsive su MDN&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Il &lt;strong&gt;lazy-loading delle immagini&lt;/strong&gt; è una tecnica che velocizza il rendering del tuo sito web &lt;strong&gt;posticipando il caricamento delle immagini below-the-fold&lt;/strong&gt; a quando &lt;strong&gt;entrano nel viewport&lt;/strong&gt;. Oltre alle prestazioni, questo ti consente anche di risparmiare larghezza di banda e denaro, ad esempio se paghi un servizio CDN per le tue immagini.&lt;/p&gt;
&lt;h2 id=&quot;prima-l-above-the-fold&quot; tabindex=&quot;-1&quot;&gt;Prima l&#39;above-the-fold &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#prima-l-above-the-fold&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Tieni a mente che l&#39;uso di uno script per il &lt;strong&gt;lazy-loading delle immagini è un&#39;attività basata su JavaScript&lt;/strong&gt; ed è &lt;strong&gt;sensibilmente più lento rispetto al normale caricamento delle immagini&lt;/strong&gt; (d&#39;ora in poi chiamato &lt;em&gt;eager loading&lt;/em&gt;), che inizia non appena viene analizzato il documento HTML.&lt;/p&gt;
&lt;p&gt;☝️ Per questo motivo, la best practice consiste nel &lt;strong&gt;caricare immediatamente (eager) le immagini above-the-fold&lt;/strong&gt; e caricare in modalità &lt;strong&gt;lazy solo le immagini below-the-fold&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;A questo punto, di solito ci si chiede:&lt;/p&gt;
&lt;p&gt;💬 &lt;em&gt;Il mio sito è responsive, come faccio a sapere quante immagini saranno&lt;/em&gt; above-the-fold &lt;em&gt;al caricamento della pagina?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;La risposta è: contale! Apri la pagina web in un browser, ridimensiona il viewport alle dimensioni più comuni (smartphone, computer e tablet) magari utilizzando lo strumento di emulazione dei dispositivi, e contale.&lt;/p&gt;
&lt;p&gt;Se vedi 4 immagini &lt;em&gt;above-the-fold&lt;/em&gt; su uno smartphone e solo la parte superiore di altre 4 su desktop, sii prudente e carica immediatamente (eager) solo le prime 4.&lt;/p&gt;
&lt;h2 id=&quot;e-ora-un-po-di-codice&quot; tabindex=&quot;-1&quot;&gt;E ora un po&#39; di codice! &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#e-ora-un-po-di-codice&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ecco il markup HTML di un&#39;immagine responsive caricata immediatamente (&lt;em&gt;eager&lt;/em&gt;).&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Caricata immediatamente (eager),
     solo above-the-fold --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Eager above&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220x280.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
    220x280.jpg 220w,
    440x560.jpg 440w
  &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ed ecco il markup per caricare un&#39;immagine responsive in modalità &lt;em&gt;lazy&lt;/em&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Caricata in modalità lazy,
     solo below-the-fold --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Lazy below&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220x280.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220x280.jpg 220w,
    440x560.jpg 440w&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Vuoi mostrare un&#39;anteprima a bassa risoluzione mentre le immagini lazy si stanno caricando? Puoi farlo inserendo una piccola immagine di bassa qualità nel tag &lt;code&gt;src&lt;/code&gt;, come nell&#39;esempio seguente.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Caricata in modalità lazy,
     + anteprima a bassa risoluzione,
     solo below-the-fold --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Lazy below con anteprima&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;11x14.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220x280.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220x280.jpg 220w,
    440x560.jpg 440w&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;http://verlok.github.io/vanilla-lazyload/demos/image_srcset_lazy_sizes.html&quot;&gt;Apri la demo 👀&lt;/a&gt;, quindi apri gli &lt;strong&gt;strumenti per sviluppatori&lt;/strong&gt; del browser e vai alla &lt;strong&gt;scheda Rete (Network)&lt;/strong&gt;. Vedrai che le prime 2 immagini vengono caricate immediatamente (&lt;em&gt;eager&lt;/em&gt;) appena la pagina si apre, mentre le restanti vengono caricate in modalità &lt;em&gt;lazy&lt;/em&gt; &lt;strong&gt;man mano che scorri verso il basso&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Stiamo usando il tag HTML &lt;code&gt;img&lt;/code&gt; e non il tag &lt;code&gt;picture&lt;/code&gt;, poiché quest&#39;ultimo non è necessario in questo caso. Approfondirò i casi d&#39;uso del tag &lt;code&gt;picture&lt;/code&gt; più avanti in questo articolo. ⏩ &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#casi-duso-del-tag-picture&quot;&gt;Vai direttamente ai casi d&#39;uso del tag &lt;code&gt;picture&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;inclusione-dello-script&quot; tabindex=&quot;-1&quot;&gt;Inclusione dello script &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#inclusione-dello-script&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Per caricare le immagini lazy quando entrano nel viewport, hai bisogno di uno script di lazy-loading come &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt;, uno script leggero (2.5 kb gzipped), velocissimo, configurabile e ottimizzato per la SEO che ho creato e continuo a migliorare costantemente dal 2014.&lt;/p&gt;
&lt;p&gt;Ecco il modo più semplice per includerlo nella tua pagina.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cdn.jsdelivr.net/npm/vanilla-lazyload@18.0.0/dist/lazyload.min.js&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Dai un&#39;occhiata alla documentazione per &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/#-getting-started---script&quot;&gt;scoprire altri modi per includere LazyLoad&lt;/a&gt; nelle tue pagine web, come l&#39;utilizzo di uno script &lt;code&gt;async&lt;/code&gt; con auto-inizializzazione, l&#39;uso di RequireJS, WebPack o Rollup.&lt;/p&gt;
&lt;h3 id=&quot;inizializzazione-di-lazyload&quot; tabindex=&quot;-1&quot;&gt;Inizializzazione di LazyLoad &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#inizializzazione-di-lazyload&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;L&#39;inclusione dello script vanilla-lazyload ti fornisce la classe JS &lt;code&gt;LazyLoad&lt;/code&gt; che puoi usare per caricare le immagini identificate dalla classe CSS &lt;code&gt;lazy&lt;/code&gt;. Devi creare un&#39;istanza di &lt;code&gt;LazyLoad&lt;/code&gt; in questo modo:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; lazyLoad &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LazyLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Le tue impostazioni personalizzate vanno qui&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;minimizzare-il-reflow-del-layout&quot; tabindex=&quot;-1&quot;&gt;Minimizzare il reflow del layout &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#minimizzare-il-reflow-del-layout&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Quando usi il lazy loading, le immagini che non hanno ancora iniziato a caricarsi collassano a un&#39;altezza pari a &lt;code&gt;0&lt;/code&gt;, per poi espandersi una volta avviato il caricamento. Questo reflow del layout renderebbe il tuo sito scattoso (janky), quindi è una best practice &lt;strong&gt;stabilizzare il layout&lt;/strong&gt; occupando lo spazio esatto che le immagini occuperanno una volta caricate, prima ancora che inizi il caricamento.&lt;/p&gt;
&lt;p&gt;La soluzione universale per farlo è utilizzare il trucco del padding verticale (padding hack), mentre in futuro sarà possibile utilizzare la proprietà CSS &lt;code&gt;aspect-ratio&lt;/code&gt; (al momento della scrittura, è &lt;a href=&quot;https://twitter.com/Una/status/1260980901934137345&quot;&gt;disponibile&lt;/a&gt; solo su Chrome Canary).&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.image-wrapper&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 150%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* ☝️ altezza immagine / larghezza immagine * 100% */&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; relative&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.image&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ecco anche un utile mixin SASS per farlo (fonte: &lt;a href=&quot;https://css-tricks.com/snippets/sass/maintain-aspect-ratio-mixin/&quot;&gt;CSS-Tricks&lt;/a&gt;).&lt;/p&gt;
&lt;pre class=&quot;language-scss&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;@mixin&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;aspect-ratio&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; relative&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;&lt;span class=&quot;token parent important&quot;&gt;&amp;amp;&lt;/span&gt;:before &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;padding-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$height&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;&gt; .content &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Maggiori informazioni in &lt;a href=&quot;http://andyshora.com/css-image-container-padding-hack.html&quot;&gt;Sizing Fluid Image Containers with a Little CSS Padding Hack&lt;/a&gt; di Andy Shora.&lt;/p&gt;
&lt;h3 id=&quot;evitare-l-effetto-immagini-rotte&quot; tabindex=&quot;-1&quot;&gt;Evitare l&#39;effetto immagini &amp;quot;rotte&amp;quot; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#evitare-l-effetto-immagini-rotte&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Per evitare che le immagini lazy appaiano come rotte, anche solo per un breve istante, usa il CSS. Nascondi le immagini che non hanno ancora impostato né l&#39;attributo &lt;code&gt;src&lt;/code&gt; né &lt;code&gt;srcset&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;img:not([src]):not([srcset])&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;visibility&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;nessun-polyfill-richiesto&quot; tabindex=&quot;-1&quot;&gt;Nessun polyfill richiesto &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#nessun-polyfill-richiesto&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Potresti essere tentato di aggiungere uno o più polyfill per supportare Internet Explorer (&lt;em&gt;sì, l&#39;ho nominato ed è il 2020&lt;/em&gt;). Non farlo, &lt;strong&gt;non ne hai bisogno&lt;/strong&gt;. Ti spiego perché:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Immagini responsive:&lt;/em&gt; Internet Explorer non supporta le immagini responsive, mas non serve un polyfill poiché &lt;abbr title=&quot;Internet Explorer&quot;&gt;IE&lt;/abbr&gt; si adatta (degrada) elegantemente mostrando &lt;strong&gt;l&#39;immagine specificata nell&#39;attributo &lt;code&gt;src&lt;/code&gt;&lt;/strong&gt;. Ti basterà quindi scegliere un&#39;immagine adatta a uno schermo desktop standard, inserirla nell&#39;attributo &lt;code&gt;src&lt;/code&gt; e sei a posto.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;IntersectionObserver:&lt;/em&gt; Internet Explorer non supporta l&#39;API &lt;code&gt;IntersectionObserver&lt;/code&gt;, che viene utilizzata da vanilla-lazyload, ma non è necessario fornire un polyfill poiché vanilla-lazyload rileverà il supporto per quell&#39;API e, in caso di mancanza, caricherà immediatamente tutte le immagini. Questo produce lo stesso risultato che si otterrebbe senza usare LazyLoad sulla pagina, ma senza generare errori.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Il che è ottimo, visto che Internet Explorer oggi non è usato da più del 5% degli utenti, e Microsoft lo sta silenziosamente sostituendo con &lt;a href=&quot;https://www.microsoft.com/edge&quot;&gt;Edge&lt;/a&gt; tramite Windows Update.&lt;/p&gt;
&lt;p&gt;In ogni caso, se per qualche motivo vuoi che funzioni esattamente allo stesso modo su Internet Explorer, puoi includere il polyfill di IntersectionObserver prima di vanilla-lazyload.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Non farlo se non sei sicuro! Leggi sopra --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cdn.jsdelivr.net/npm/intersection-observer@0.10.0/intersection-observer.js&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cdn.jsdelivr.net/npm/vanilla-lazyload@18.0.0/dist/lazyload.min.js&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;mettiamo-tutto-insieme&quot; tabindex=&quot;-1&quot;&gt;Mettiamo tutto insieme &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#mettiamo-tutto-insieme&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Per tua comodità, ecco tutto il codice HTML, JS e CSS riunito.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Caricata immediatamente (eager),
     solo above-the-fold --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Eager above&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220x280.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
    220x280.jpg 220w,
    440x560.jpg 440w
  &lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Caricata in modalità lazy,
     solo below-the-fold --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Lazy below&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220x280.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220x280.jpg 220w,
    440x560.jpg 440w&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; lazyLoad &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LazyLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;elements_selector&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;.lazy&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;cancel_on_exit&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/*
Contenitore delle immagini per occupare spazio
quando le immagini non sono ancora caricate
*/&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.image-wrapper&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 150%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* ☝️ altezza immagine / larghezza immagine * 100% */&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; relative&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.image&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* ...altre regole di posizionamento */&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/*
Nascondi le immagini &quot;rotte&quot; prima
che inizino a caricare
*/&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;img:not([src]):not([srcset])&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;visibility&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;E questo è tutto per quanto riguarda il semplice tag &lt;code&gt;img&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;casi-d-uso-del-tag-picture&quot; tabindex=&quot;-1&quot;&gt;Casi d&#39;uso del tag picture &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#casi-d-uso-del-tag-picture&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Fino ad ora ho parlato del tag &lt;code&gt;img&lt;/code&gt; con gli attributi &lt;code&gt;srcset&lt;/code&gt; e &lt;code&gt;sizes&lt;/code&gt;, che rappresenta la soluzione per la stragrande maggioranza delle immagini responsive che potresti dover usare in un sito o in un&#39;applicazione web. Ora, in quali casi dovresti invece usare il tag &lt;code&gt;picture&lt;/code&gt;?&lt;/p&gt;
&lt;h3 id=&quot;rapporto-larghezza-altezza-differente-art-direction&quot; tabindex=&quot;-1&quot;&gt;Rapporto larghezza/altezza differente (Art Direction) &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#rapporto-larghezza-altezza-differente-art-direction&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Caso d&#39;uso: devi mostrare immagini con un &lt;strong&gt;rapporto larghezza/altezza differente&lt;/strong&gt; a seconda di una media query. Ad esempio, vuoi mostrare &lt;em&gt;immagini verticali (portrait)&lt;/em&gt; su dispositivi mobili e verticali, e &lt;em&gt;immagini orizzontali (landscape)&lt;/em&gt; su viewport più ampi come tablet e computer.&lt;/p&gt;
&lt;p&gt;Ecco il codice di cui avrai bisogno in questo caso. Per caricare le immagini immediatamente (eager), usa semplicemente gli attributi standard &lt;code&gt;src&lt;/code&gt; e &lt;code&gt;srcset&lt;/code&gt;, senza il prefisso &lt;code&gt;data-&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: 1024px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;1024x576.jpg 1x,
      2048x1152.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(max-width: 1023px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;640x960.jpg 1x,
      1280x1920.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Ritratto o panorama&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;1024x576.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;http://verlok.github.io/vanilla-lazyload/demos/picture_media.html&quot;&gt;Apri la demo 👀&lt;/a&gt;, quindi apri gli &lt;strong&gt;strumenti per sviluppatori&lt;/strong&gt; del browser e vai alla &lt;strong&gt;scheda Rete (Network)&lt;/strong&gt;. Vedrai che viene scaricata solo la sorgente d&#39;immagine corrispondente alla prima media query soddisfatta.&lt;/p&gt;
&lt;h3 id=&quot;caricare-formati-moderni-come-webp-e-jpeg2000&quot; tabindex=&quot;-1&quot;&gt;Caricare formati moderni come WebP e Jpeg2000 &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#caricare-formati-moderni-come-webp-e-jpeg2000&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Caso d&#39;uso: vuoi che sia il browser a scegliere la sorgente per &lt;strong&gt;caricare un formato moderno come WebP o Jpeg2000&lt;/strong&gt; in base al supporto per quel determinato formato.&lt;/p&gt;
&lt;p&gt;Avrai bisogno del tag &lt;code&gt;source&lt;/code&gt; e dell&#39;attributo &lt;code&gt;type&lt;/code&gt; che contiene il MIME type delle immagini nell&#39;attributo &lt;code&gt;data-&lt;/code&gt;/&lt;code&gt;srcset&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image/jp2&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;1024x576.jp2 1x,
      2048x1152.jp2 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image/webp&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;1024x576.webp 1x,
      2048x1152.webp 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;1024x576.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;1024x576.jpg 1x,
      2048x1152.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;data-sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;1024px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Jp2, WebP o Jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;http://verlok.github.io/vanilla-lazyload/demos/picture_type_webp.html&quot;&gt;Apri la demo 👀&lt;/a&gt;, apri gli &lt;strong&gt;strumenti per sviluppatori&lt;/strong&gt; del browser e vai alla &lt;strong&gt;scheda Rete (Network)&lt;/strong&gt;. Vedrai che scaricherà solo la sorgente dell&#39;immagine corrispondente al primo formato supportato dal tuo browser.&lt;/p&gt;
&lt;p&gt;💬 &lt;em&gt;Questo markup non è un po&#39; troppo lungo per una singola immagine?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Sì, lo è. E se hai budget da investire nell&#39;ottimizzazione delle immagini, ci sono altri modi per farlo. La maggior parte dei server di immagini basati su cloud presenti sul mercato serve automaticamente diversi formati di immagine allo stesso URL. Ciò significa che puoi richiedere &lt;code&gt;1024x576.jpg&lt;/code&gt; e ottenere un file WebP o Jpeg2000 di conseguenza. &lt;a href=&quot;https://cloudinary.com/&quot;&gt;Cloudinary&lt;/a&gt; e &lt;a href=&quot;https://www.akamai.com/it/it/products/performance/image-and-video-manager.jsp&quot;&gt;Akamai Image &amp;amp; Video Manager&lt;/a&gt; fanno proprio questo, tra gli altri.&lt;/p&gt;
&lt;h3 id=&quot;limitare-la-fedelta-delle-immagini-a-2x&quot; tabindex=&quot;-1&quot;&gt;Limitare la fedeltà delle immagini a 2x &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#limitare-la-fedelta-delle-immagini-a-2x&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Con la diffusione di schermi ad altissima densità &amp;quot;super retina&amp;quot; nei dispositivi di fascia alta più recenti (come le serie iPhone 12 o Google Pixel), limitare la fedeltà dell&#39;immagine a 2x porta a un notevole miglioramento nei tempi di download, senza alcuna perdita di qualità percepibile per gli utenti.&lt;/p&gt;
&lt;p&gt;👉 &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/capping-image-fidelity-2x-minimize-loading-time&quot;&gt;Ecco una nuova best practice su come fare.&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;lazy-loading-nativo&quot; tabindex=&quot;-1&quot;&gt;Lazy loading nativo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#lazy-loading-nativo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Forse avrai sentito o letto dell&#39;arrivo del &lt;a href=&quot;https://web.dev/native-lazy-loading/&quot;&gt;lazy-loading nativo&lt;/a&gt; sul web. Fantastico, vero? A partire da maggio 2020, è supportato da Chrome, Firefox, Edge, Opera e, &lt;em&gt;dietro un flag&lt;/em&gt;, da Safari.&lt;/p&gt;
&lt;p&gt;Quindi il supporto al 100% dei browser non è ancora arrivato, ma nel caso in cui tu voglia abilitarlo sui browser supportati, puoi optare per il &lt;a href=&quot;https://www.smashingmagazine.com/2019/05/hybrid-lazy-loading-progressive-migration-native/&quot;&gt;lazy loading ibrido&lt;/a&gt; impostando l&#39;opzione &lt;code&gt;use_native&lt;/code&gt; di vanilla-lazyload su &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LazyLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;use_native&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;funzionalita-a-cui-potresti-dover-rinunciare&quot; tabindex=&quot;-1&quot;&gt;Funzionalità a cui potresti dover rinunciare &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#funzionalita-a-cui-potresti-dover-rinunciare&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Se opti per il lazy-loading nativo o quello ibrido, potresti perdere alcune &lt;strong&gt;funzionalità offerte dal lazy-loading gestito da JavaScript&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;applicazione automatica delle classi&lt;/strong&gt; in base agli eventi (&lt;code&gt;loading&lt;/code&gt;, &lt;code&gt;loaded&lt;/code&gt;, ecc.)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;riprovo automatico del caricamento&lt;/strong&gt; delle immagini in caso di errore di rete non appena si torna online&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;cancellazione del download&lt;/strong&gt; quando le immagini escono dal viewport mentre si stanno ancora caricando, in modo da &lt;strong&gt;dare priorità a quelle nuove&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;callback sugli eventi attivati&lt;/strong&gt; (ingresso/uscita dal viewport, caricamento iniziato/finito, ecc.)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Rifletti attentamente prima di passare al lazy-loading nativo. Se la mancanza di queste funzioni non rappresenta un problema per te, allora puoi procedere tranquillamente.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;conclusioni&quot; tabindex=&quot;-1&quot;&gt;Conclusioni &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#conclusioni&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ecco un riassunto:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Usa &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/&quot;&gt;vanilla-lazyload&lt;/a&gt; per gestire il caricamento delle tue immagini.&lt;/li&gt;
&lt;li&gt;Non caricare tutte le immagini in modalità lazy, ma solo quelle &lt;em&gt;below-the-fold&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Usa il tag &lt;code&gt;img&lt;/code&gt; per le immagini responsive semplici&lt;/li&gt;
&lt;li&gt;Usa il tag &lt;code&gt;picture&lt;/code&gt; per:
&lt;ul&gt;
&lt;li&gt;modificare il rapporto larghezza/altezza delle immagini a specifiche media query&lt;/li&gt;
&lt;li&gt;servire in modo condizionale le immagini in formati moderni come WebP o Jpeg2000&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Non utilizzare alcun polyfill se non è strettamente necessario&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Buon lazy loading!&lt;/p&gt;
&lt;h3 id=&quot;riguardo-questo-articolo&quot; tabindex=&quot;-1&quot;&gt;Riguardo questo articolo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#riguardo-questo-articolo&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Se qualcosa non è chiaro o ritieni possa essere migliorato, fammelo sapere nei commenti o &lt;a href=&quot;https://twitter.com/verlok/&quot;&gt;scrivimi su Twitter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;☕ Se hai trovato utile questo articolo, puoi esprimere la tua gratitudine &lt;a href=&quot;https://ko-fi.com/verlok&quot;&gt;offrendomi un caffè&lt;/a&gt;. ☕&lt;/p&gt;
&lt;h3 id=&quot;risorse-utili&quot; tabindex=&quot;-1&quot;&gt;Risorse utili &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp/#risorse-utili&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://alistapart.com/article/responsive-images-in-practice&quot;&gt;Responsive images in practice&lt;/a&gt; @ A List Apart&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images&quot;&gt;Responsive images&lt;/a&gt; @ Mozilla Developer Network&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://css-tricks.com/responsive-images-css/&quot;&gt;Responsive images in CSS&lt;/a&gt; @ CSS Tricks&lt;/li&gt;
&lt;li&gt;Sito del &lt;a href=&quot;https://responsiveimages.org&quot;&gt;Responsive Images Community Group&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
	</entry>
	
	<entry>
		<title>Come usare in modo produttivo il nuovo browser Microsoft Edge basato su Chromium</title>
		<link href="https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/"/>
		<updated>2020-01-16T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/</id>
		<content type="html">&lt;p&gt;Ecco una guida pratica su come usare in modo produttivo il nuovo browser Microsoft Edge basato su Chromium: scaricarlo, cambiare il motore di ricerca predefinito, installare estensioni e altro ancora.&lt;/p&gt;
&lt;h2 id=&quot;indice&quot; tabindex=&quot;-1&quot;&gt;Indice &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/#indice&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Scaricare Microsoft Edge&lt;/li&gt;
&lt;li&gt;Modificare il motore di ricerca predefinito&lt;/li&gt;
&lt;li&gt;Installare estensioni dal Chrome Web Store&lt;/li&gt;
&lt;li&gt;Impostare il tema scuro&lt;/li&gt;
&lt;li&gt;Configurare uno o più profili&lt;/li&gt;
&lt;li&gt;Diventare un insider&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;download-per-qualsiasi-piattaforma&quot; tabindex=&quot;-1&quot;&gt;Download per qualsiasi piattaforma &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/#download-per-qualsiasi-piattaforma&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Non importa se utilizzi Windows 10, 8, 7 o macOS, puoi &lt;a href=&quot;https://www.microsoft.com/edge&quot;&gt;scaricare Microsoft Edge&lt;/a&gt; per il tuo computer.&lt;/p&gt;
&lt;h2 id=&quot;modificare-il-motore-di-ricerca-predefinito&quot; tabindex=&quot;-1&quot;&gt;Modificare il motore di ricerca predefinito &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/#modificare-il-motore-di-ricerca-predefinito&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Dopo averlo installato, la prima cosa che vorrai fare è cambiare il tuo motore di ricerca predefinito impostando Google o DuckDuckGo (a meno che tu non preferisca davvero Bing). Puoi farlo dal pannello delle Impostazioni, nella scheda Privacy e servizi.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Clicca sul pulsante &lt;code&gt;...&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Seleziona &amp;quot;Impostazioni&amp;quot;&lt;/li&gt;
&lt;li&gt;Seleziona &amp;quot;Privacy e servizi&amp;quot; nel menu a sinistra&lt;/li&gt;
&lt;li&gt;(scorri fino in fondo)&lt;/li&gt;
&lt;li&gt;Clicca su &amp;quot;Barra degli indirizzi&amp;quot;&lt;/li&gt;
&lt;li&gt;Seleziona il tuo motore di ricerca preferito dal menu a discesa &amp;quot;Motore di ricerca utilizzato nella barra degli indirizzi&amp;quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Buon utilizzo!&lt;/p&gt;
&lt;h2 id=&quot;installare-estensioni&quot; tabindex=&quot;-1&quot;&gt;Installare estensioni &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/#installare-estensioni&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Microsoft Edge ha il suo marketplace per le estensioni, ma su Microsoft Edge puoi anche &lt;strong&gt;installare estensioni dal Chrome Web Store&lt;/strong&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.microsoft.com/en-us/store/collections/edgeextensions/&quot;&gt;Estensioni per Microsoft Edge&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://chrome.google.com/webstore/category/extensions&quot;&gt;Estensioni dal Chrome Web Store&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Quando visiti il Chrome Web Store, Edge mostra una barra blu in alto che ti informa che puoi installare estensioni da lì. Fai semplicemente clic sul pulsante &amp;quot;Consenti estensioni da altri store&amp;quot; e sei pronto a partire.&lt;/p&gt;
&lt;h2 id=&quot;come-impostare-il-tema-scuro&quot; tabindex=&quot;-1&quot;&gt;Come impostare il tema scuro &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/#come-impostare-il-tema-scuro&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se come me ami i temi scuri per gli strumenti di sviluppo, puoi attivare il tema scuro dal pannello Impostazioni, nella scheda Aspetto.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Clicca sul pulsante &lt;code&gt;...&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Seleziona &amp;quot;Impostazioni&amp;quot;&lt;/li&gt;
&lt;li&gt;Seleziona &amp;quot;Aspetto&amp;quot;&lt;/li&gt;
&lt;li&gt;Seleziona &amp;quot;Scuro&amp;quot; dal menu a discesa &amp;quot;Tema&amp;quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;c-e-dell-altro-i-profili&quot; tabindex=&quot;-1&quot;&gt;C&#39;è dell&#39;altro? I profili &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/#c-e-dell-altro-i-profili&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se sei un utente Chrome, al tuo primo utilizzo di Microsoft Edge tutto verrà magicamente migrato da Chrome a Edge. Almeno, questo è quello che è successo a me quando ho iniziato a usare Edge Dev qualche mese fa.&lt;/p&gt;
&lt;p&gt;Potrebbe interessarti creare uno o più profili e configurare le opzioni di sincronizzazione, in modo che quando usi Edge sugli altri tuoi dispositivi (PC, altri PC, Mac, ecc.) troverai le tue password, i dati di compilazione automatica e la cronologia di navigazione a portata di mano.&lt;/p&gt;
&lt;h2 id=&quot;diventa-un-insider&quot; tabindex=&quot;-1&quot;&gt;Diventa un insider &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/#diventa-un-insider&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Puoi anche diventare un insider e utilizzare le versioni preliminari di Microsoft Edge. Ci sono 3 canali: Beta, Dev e Canary.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Canary è aggiornato più frequentemente (ogni giorno) ma è anche il più instabile&lt;/li&gt;
&lt;li&gt;Beta è aggiornato meno frequentemente (ogni 6 settimane) ed è quindi il più stabile&lt;/li&gt;
&lt;li&gt;Dev è aggiornato settimanalmente ed è quindi più stabile di Canary, ma meno stabile di Beta.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Scarica una qualsiasi di queste versioni nella &lt;a href=&quot;https://www.microsoftedgeinsider.com/en-gb/download/&quot;&gt;pagina dei canali Microsoft Edge Insider&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Personalmente ho utilizzato Microsoft Edge Dev come browser principale per mesi, sia su Mac che su Windows, sia per svago che per sviluppo, con un altissimo livello di soddisfazione. Sfortunatamente, le ultime versioni Dev e Canary hanno smesso di funzionare su una delle mie macchine a partire dal 9 gennaio, ma l&#39;ho già segnalato a Microsoft e mi aspetto una soluzione a breve.&lt;/p&gt;
&lt;h2 id=&quot;e-la-fine-di-internet-explorer&quot; tabindex=&quot;-1&quot;&gt;È la fine di Internet Explorer? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/#e-la-fine-di-internet-explorer&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ci sono ancora aziende che utilizzano &lt;a href=&quot;https://www.bairesdev.com/blog/internet-explorer-history/&quot;&gt;Internet Explorer&lt;/a&gt; per motivi di compatibilità (vecchi strumenti web o siti intranet). Questa versione di Edge dispone di una &amp;quot;modalità Internet Explorer&amp;quot;, in modo che queste aziende possano finalmente impostare Microsoft Edge come browser predefinito per i propri lavoratori, che potranno così navigare sul web utilizzando un browser moderno senza compromettere il funzionamento dei loro vecchi strumenti.&lt;/p&gt;
&lt;h2 id=&quot;aiuta-il-web&quot; tabindex=&quot;-1&quot;&gt;Aiuta il web &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/how-to-productively-use-the-new-chromium-based-microsoft-edge-browser/#aiuta-il-web&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se conosci aziende che utilizzano ancora Internet Explorer per motivi di compatibilità, dovresti parlargliene.&lt;/p&gt;
&lt;p&gt;E se sei uno sviluppatore web come me, dovresti assolutamente provare Microsoft Edge sia per testare sia per sviluppare i tuoi siti web.&lt;/p&gt;
&lt;p&gt;➡ &lt;a href=&quot;https://www.microsoft.com/edge&quot;&gt;Scarica Microsoft Edge (stabile)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Buon divertimento!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Critical CSS con Jekyll e SASS</title>
		<link href="https://andreaverlicchi.eu/it/blog/critical-css-jekyll-sass-github-pages/"/>
		<updated>2019-06-17T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/critical-css-jekyll-sass-github-pages/</id>
		<content type="html">&lt;p&gt;In passato il mio blog era gestito da &lt;strong&gt;Jekyll su GitHub Pages&lt;/strong&gt; e il suo CSS era compilato usando SASS. Oggi ho deciso di migliorare ulteriormente le prestazioni integrando inline il &lt;em&gt;critical&lt;/em&gt; CSS che blocca il rendering, ma anche cercando su internet ho faticato a trovare un modo semplice per farlo. Questo post fa al caso tuo, se vuoi fare la stessa cosa.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/NLErsSG8S0-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Codice sfocato casuale&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/NLErsSG8S0-648.jpeg&quot; width=&quot;648&quot; height=&quot;432&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;h2 id=&quot;lo-stile-critical&quot; tabindex=&quot;-1&quot;&gt;Lo stile critical &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/critical-css-jekyll-sass-github-pages/#lo-stile-critical&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Nel file SASS per il critical CSS, usa la direttiva SASS &lt;code&gt;@import&lt;/code&gt; per includere tutti i partial che hanno un impatto sul layout della tua pagina. Includi anche le tue variabili (&lt;em&gt;variables&lt;/em&gt;) e mixin che potrebbero essere richiesti dai partial importati.&lt;/p&gt;
&lt;p&gt;Ad esempio, io sto importando:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;il partial &lt;code&gt;base&lt;/code&gt;, che contiene le regole di base del sito come il CSS reset e le regole tipografiche,&lt;/li&gt;
&lt;li&gt;il partial &lt;code&gt;layout&lt;/code&gt;, che definisce lo stile dell&#39;header e del layout della pagina,&lt;/li&gt;
&lt;li&gt;il partial &lt;code&gt;posts_above&lt;/code&gt;, che definisce lo stile della parte &lt;em&gt;above-the-fold&lt;/em&gt; dell&#39;elenco dei post e del dettaglio del post,&lt;/li&gt;
&lt;li&gt;il partial &lt;code&gt;utils&lt;/code&gt;, che contiene alcune classi di utilità (ad es. &lt;code&gt;visuallyHidden&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Il partial &lt;code&gt;posts_above&lt;/code&gt; inizialmente era un unico file chiamato &lt;code&gt;posts&lt;/code&gt;, ma ho deciso di dividerlo in due file separati per ottimizzare ancora di più. L&#39;altro partial, chiamato &lt;code&gt;posts_below&lt;/code&gt;, contiene le informazioni di stile per il footer del post (la sezione dell&#39;autore, il pulsante di condivisione), quindi &lt;em&gt;non&lt;/em&gt; è incluso qui.&lt;/p&gt;
&lt;p&gt;→ Crea un file &lt;code&gt;critical.scss&lt;/code&gt; all&#39;interno della cartella &lt;code&gt;includes&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;File &lt;code&gt;includes/critical.scss&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-scss&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Importa i partial per il contenuto del critical css&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;variables&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;mixins&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;base&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&quot;layout&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;posts_above&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;pages&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&quot;utils&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;IMPORTANTE: Posiziona questo file nella cartella &lt;code&gt;includes&lt;/code&gt;! Più tardi dovrai includerlo nel tuo HTML.&lt;/p&gt;
&lt;h2 id=&quot;inseriscilo-nella-sezione-head&quot; tabindex=&quot;-1&quot;&gt;Inseriscilo nella sezione &lt;code&gt;head&lt;/code&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/critical-css-jekyll-sass-github-pages/#inseriscilo-nella-sezione-head&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Inserisci il critical CSS inline all&#39;interno di un tag &lt;code&gt;style&lt;/code&gt; nella sezione &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; del tuo HTML. Puoi farlo usando il seguente codice Jekyll, basato sul motore di template Liquid utilizzato in Jekyll.&lt;/p&gt;
&lt;p&gt;→ Apri il tuo partial &lt;code&gt;head.html&lt;/code&gt;, se ne hai uno.&lt;/p&gt;
&lt;p&gt;File &lt;code&gt;includes/head.html&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-liquid&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-liquid&quot;&gt;&lt;span class=&quot;token liquid language-liquid&quot;&gt;&lt;span class=&quot;token delimiter punctuation&quot;&gt;{%&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;capture&lt;/span&gt; critical &lt;span class=&quot;token delimiter punctuation&quot;&gt;%}&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token liquid language-liquid&quot;&gt;&lt;span class=&quot;token delimiter punctuation&quot;&gt;{%&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;include&lt;/span&gt; minima_critical&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;scss &lt;span class=&quot;token delimiter punctuation&quot;&gt;%}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token liquid language-liquid&quot;&gt;&lt;span class=&quot;token delimiter punctuation&quot;&gt;{%&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;endcapture&lt;/span&gt; &lt;span class=&quot;token delimiter punctuation&quot;&gt;%}&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token liquid language-liquid&quot;&gt;&lt;span class=&quot;token delimiter punctuation&quot;&gt;{{&lt;/span&gt; critical &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function filter&quot;&gt;scssify&lt;/span&gt; &lt;span class=&quot;token delimiter punctuation&quot;&gt;}}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;il-resto-del-tuo-foglio-di-stile&quot; tabindex=&quot;-1&quot;&gt;Il resto del tuo foglio di stile &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/critical-css-jekyll-sass-github-pages/#il-resto-del-tuo-foglio-di-stile&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se il tuo sito è abbastanza semplice, puoi importare il resto dei tuoi partial all&#39;interno di un singolo file SCSS, che caricherai in modo asincrono usando JavaScript.&lt;/p&gt;
&lt;p&gt;Io, ad esempio, ho importato lì tutti i partial SASS che definiscono lo stile delle sezioni della pagina che probabilmente appariranno &lt;em&gt;below-the-fold&lt;/em&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;lo stile di evidenziazione della sintassi (syntax highlighting),&lt;/li&gt;
&lt;li&gt;lo stile del footer,&lt;/li&gt;
&lt;li&gt;lo stile della paginazione,&lt;/li&gt;
&lt;li&gt;lo stile delle icone SVG,&lt;/li&gt;
&lt;li&gt;lo stile degli iframe e delle tabelle&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;→ Inserisci il resto delle tue regole SASS all&#39;interno del tuo normale file CSS.&lt;/p&gt;
&lt;p&gt;File &lt;code&gt;assets/main.scss&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-scss&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-scss&quot;&gt;---
---

&lt;span class=&quot;token comment&quot;&gt;// Importa i partial per il contenuto below-the-fold&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;variables&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;mixins&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&quot;posts_below&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;syntax-highlighting&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&quot;footer&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;code&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;pagination&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&quot;icons&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;iframes&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;tables&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;IMPORTANTE&lt;/strong&gt;: Le due righe con tre trattini all&#39;inizio del file sono richieste da Jekyll per riconoscere ed elaborare il file come contenuto.&lt;/p&gt;
&lt;h2 id=&quot;carica-il-resto-del-foglio-di-stile&quot; tabindex=&quot;-1&quot;&gt;Carica il resto del foglio di stile &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/critical-css-jekyll-sass-github-pages/#carica-il-resto-del-foglio-di-stile&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ci sono molti modi per caricare il resto del tuo CSS usando JavaScript, ma ho deciso di usare la &lt;a href=&quot;https://www.filamentgroup.com/lab/async-css.html&quot;&gt;tecnica asincrona moderna&lt;/a&gt; che fa sì che un file CSS venga caricato con bassa priorità, per poi applicarlo alla pagina una volta caricato.&lt;/p&gt;
&lt;p&gt;File &lt;code&gt;head.html&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;link&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stylesheet&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;{{ &#39;/assets/main.css&#39; | relative_url }}&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;nope!&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token special-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;onload&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token value javascript language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;media&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;all&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Funziona!&lt;/p&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/critical-css-jekyll-sass-github-pages/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Integrare inline la parte critica del tuo CSS fa sì che le tue pagine vengano visualizzate più velocemente, poiché il CSS si trova nel percorso di rendering critico (critical rendering path) del browser.&lt;/p&gt;
&lt;p&gt;Fai una prova! Se hai commenti, fammi sapere nella sezione commenti qui sotto!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Web Share API, il passo successivo alla PWA</title>
		<link href="https://andreaverlicchi.eu/it/blog/web-share-api-step-by-step/"/>
		<updated>2019-06-14T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/web-share-api-step-by-step/</id>
		<content type="html">&lt;p&gt;Oggi ho sperimentato con la Web Share API e l&#39;ho implementata su questo sito, tanto per iniziare. Ecco cosa ho fatto e come puoi implementarla sul tuo sito.&lt;/p&gt;
&lt;p&gt;Dopo aver trasformato questo sito in una Progressive Web Application, ho rimosso lo script AddThis che veniva utilizzato per aggiungere i pulsanti di condivisione alla fine di ogni post, perché rallentava il sito. Mi sono poi reso conto che, dopo aver aggiunto il sito alla schermata iniziale del telefono come app standalone, gli utenti non potevano più condividere i post.&lt;/p&gt;
&lt;h2 id=&quot;web-share-api-in-soccorso&quot; tabindex=&quot;-1&quot;&gt;Web Share API in soccorso! &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/web-share-api-step-by-step/#web-share-api-in-soccorso&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ho aggiunto il seguente script alle pagine dei post del mio sito:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Rileva il supporto per la funzionalità di condivisione web&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; supportsShare &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;share&quot;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; navigator&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Nessun supporto?&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// - Aggiunge una classe &quot;noShare&quot; al documento&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// - Non fa nient&#39;altro&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;supportsShare&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;documentElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;classList&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;noShare&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Supportato? Recupera:&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// - il pulsante di condivisione (elemento DOM)&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// - il canonicalUrl della pagina&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// - il titolo della pagina&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; shareButton &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;.post-share&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; canonicalUrl &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;link[rel=canonical]&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getAttribute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;href&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; title &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;innerText&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Aggiunge un listener al pulsante di condivisione&lt;/span&gt;
  shareButton&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;click&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Chiama navigator.share con il titolo e l&#39;URL canonico&lt;/span&gt;
    navigator
      &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;share&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token literal-property property&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; title&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token literal-property property&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; canonicalUrl
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// Fai quello che vuoi qui&lt;/span&gt;
        console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Grazie per la condivisione!&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// Gestisci gli errori qui&lt;/span&gt;
        console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Condivisione fallita&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Poi, per nascondere i pulsanti di condivisione tramite CSS quando la classe &lt;code&gt;noShare&lt;/code&gt; viene aggiunta al documento:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.noShare .post-share&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Facile, no?&lt;/p&gt;
&lt;p&gt;Il &lt;a href=&quot;https://caniuse.com/#feat=web-share&quot;&gt;supporto per la Web Share API&lt;/a&gt; è ancora limitato, ma per lo meno è supportato da Safari e Chrome per Android, quindi aiuterà chiunque abbia installato la tua PWA sulla schermata iniziale del proprio smartphone.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Trasformare il mio blog in una Progressive Web Application</title>
		<link href="https://andreaverlicchi.eu/it/blog/this-website-pwa/"/>
		<updated>2019-06-10T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/this-website-pwa/</id>
		<content type="html">&lt;p&gt;Alcuni colleghi ed io abbiamo partecipato a un Hackathon di Google sulle Progressive Web Application e abbiamo imparato molto, così ho deciso di abilitare questo sito web come PWA. Ecco cosa ho fatto...&lt;/p&gt;
&lt;p&gt;Per rendere un&#39;app installabile, è necessario aggiungere un manifest al sito web. Ecco il manifest di questo sito.&lt;/p&gt;
&lt;pre class=&quot;language-json&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Andrea Verlicchi’s Blog&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;short_name&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;AV&#39;s Blog&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;icons&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;src&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/android-chrome-192x192.png?v=wAXeG66EQW&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;sizes&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;192x192&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;image/png&quot;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;src&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/android-chrome-512x512.png?v=wAXeG66EQW&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;sizes&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;512x512&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;image/png&quot;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;theme_color&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#D90009&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;background_color&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#977f34&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;display&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;standalone&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;start_url&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Se vuoi abilitare il tuo sito web come PWA, ti consiglio di iniziare leggendo la guida &lt;a href=&quot;https://developers.google.com/web/tools/workbox/guides/get-started&quot;&gt;Workbox Getting Started&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;il-file-del-service-worker&quot; tabindex=&quot;-1&quot;&gt;Il file del Service Worker &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/this-website-pwa/#il-file-del-service-worker&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Utilizzo &lt;a href=&quot;https://developers.google.com/web/tools/workbox/&quot;&gt;Workbox&lt;/a&gt; per abilitare i Service Worker e gestire le strategie di cache, ecc.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token function&quot;&gt;importScripts&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/*
 * REGOLE DI ROUTING
 */&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Caching di tutti i file JS con la strategia Stale While Revalidate&lt;/span&gt;
workbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;routing&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;registerRoute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token regex&quot;&gt;&lt;span class=&quot;token regex-delimiter&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token regex-source language-regex&quot;&gt;&#92;.js$&lt;/span&gt;&lt;span class=&quot;token regex-delimiter&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;workbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strategies&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;StaleWhileRevalidate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;cacheName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;js-cache&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Caching di tutti i file CSS con la strategia Stale While Revalidate&lt;/span&gt;
workbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;routing&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;registerRoute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token regex&quot;&gt;&lt;span class=&quot;token regex-delimiter&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token regex-source language-regex&quot;&gt;&#92;.css$&lt;/span&gt;&lt;span class=&quot;token regex-delimiter&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;workbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strategies&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;StaleWhileRevalidate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;cacheName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;css-cache&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Caching di tutti i file immagine con la strategia Cache First&lt;/span&gt;
workbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;routing&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;registerRoute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token regex&quot;&gt;&lt;span class=&quot;token regex-delimiter&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token regex-source language-regex&quot;&gt;&#92;.(?:png|jpg|jpeg|svg)$&lt;/span&gt;&lt;span class=&quot;token regex-delimiter&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;workbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strategies&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;CacheFirst&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;cacheName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;image-cache&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;plugins&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;workbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;expiration&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Plugin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token literal-property property&quot;&gt;maxEntries&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token literal-property property&quot;&gt;maxAgeSeconds&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;7&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;24&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Caching dell&#39;HTML di tutti i post con la strategia Network First&lt;/span&gt;
workbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;routing&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;registerRoute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token regex&quot;&gt;&lt;span class=&quot;token regex-delimiter&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token regex-source language-regex&quot;&gt;&#92;/[^&#92;/]+&#92;/$&lt;/span&gt;&lt;span class=&quot;token regex-delimiter&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;workbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strategies&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;NetworkFirst&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;cacheName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;posts-cache&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;plugins&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;workbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;expiration&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Plugin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token literal-property property&quot;&gt;maxEntries&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ho temporaneamente disabilitato il precaching delle altre pagine perché ho scoperto che queste informazioni vengono poi aggiunte alla strategia di routing con la strategia Cache First, il che non è ideale per fare in modo che il sito recuperi sempre informazioni aggiornate.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/*
 * PRECACHING
 */&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// DISATTIVATO PERCHÉ QUESTE RISORSE SAREBBERO SOLO CACHE-FIRST!&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;/*workbox.precaching.precacheAndRoute([
  { url: &#39;/&#39;, revision: &#39;20190607&#39; },
  { url: &#39;/about/&#39;, revision: &#39;20190607&#39; },
  { url: &#39;/contact/&#39;, revision: &#39;20190607&#39; }
]);*/&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ma sto studiando e approfondendo come gestire questa cosa.&lt;/p&gt;
&lt;h2 id=&quot;risultati&quot; tabindex=&quot;-1&quot;&gt;Risultati &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/this-website-pwa/#risultati&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il risultato è che questo sito web ora è:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Installabile&lt;/li&gt;
&lt;li&gt;Accessibile offline&lt;/li&gt;
&lt;li&gt;Moderno :)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Se hai suggerimenti o commenti, per favore &lt;a href=&quot;https://andreaverlicchi.eu/contact/&quot;&gt;contattami&lt;/a&gt; e fammi sapere!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Un fantastico articolo sul lazy loading ibrido</title>
		<link href="https://andreaverlicchi.eu/it/blog/hybrid-lazy-loading-smashing-magazine-article/"/>
		<updated>2019-05-16T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/hybrid-lazy-loading-smashing-magazine-article/</id>
		<content type="html">&lt;p&gt;Il &lt;time datetime=&quot;2019-05-06&quot;&gt;6 maggio 2019&lt;/time&gt; ho scritto il mio primo articolo su &lt;strong&gt;Smashing Magazine&lt;/strong&gt;: &lt;a href=&quot;https://www.smashingmagazine.com/2019/05/hybrid-lazy-loading-progressive-migration-native/&quot;&gt;Lazy Loading Ibrido: Una Migrazione Progressiva Al Lazy Loading Nativo&lt;/a&gt;.&lt;/p&gt;
&lt;figure&gt;
  &lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/qontc8aECm-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Uno screenshot dell&#39;articolo su Smashing Magazine&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/qontc8aECm-648.png&quot; width=&quot;648&quot; height=&quot;318&quot;&gt;&lt;/picture&gt;
  &lt;figcaption&gt;Uno screenshot dell&#39;articolo su Smashing Magazine&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;blockquote&gt;
&lt;p&gt;Il lazy loading nativo sta arrivando sul web. Poiché non dipende da JavaScript, rivoluzionerà il modo in cui oggi carichiamo i contenuti in modalità lazy, rendendo più semplice per gli sviluppatori gestire immagini e iframe. Ma non è una funzionalità che possiamo polyfillare, e ci vorrà del tempo prima che diventi utilizzabile su tutti i browser. In questo articolo imparerai come funziona e come puoi sostituire progressivamente il tuo lazy loading basato su JavaScript con la sua alternativa nativa, grazie al lazy loading ibrido.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Nelle ultime settimane, potresti aver sentito o letto parlare del lazy loading nativo, in arrivo su Chromium 75 nei prossimi mesi.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;“Sì, ottima notizia, ma dovremo aspettare che tutti i browser lo supportino.”&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Se questo è stato il primo pensiero che ti è passato per la testa, continua a leggere. Cercherò di convincerti del contrario.&lt;/p&gt;
&lt;p&gt;Iniziamo con un confronto tra il lazy loading nativo e il caro vecchio caricamento gestito da JavaScript.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://www.smashingmagazine.com/2019/05/hybrid-lazy-loading-progressive-migration-native/&quot;&gt;Leggi l&#39;articolo completo&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Lazy loading nativo e fallback js con vanilla-lazyload 12</title>
		<link href="https://andreaverlicchi.eu/it/blog/native-lazy-loading-with-vanilla-lazyload/"/>
		<updated>2019-04-11T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/native-lazy-loading-with-vanilla-lazyload/</id>
		<content type="html">&lt;p&gt;Il 6 aprile 2019, Addy Osmani ha scritto sul &lt;a href=&quot;https://addyosmani.com/blog/lazy-loading/&quot;&gt;lazy-loading nativo delle immagini&lt;/a&gt;. Due giorni dopo Yvain, uno sviluppatore front-end di Parigi, &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/issues/331&quot;&gt;mi ha chiesto&lt;/a&gt; se il mio &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/&quot;&gt;vanilla-lazyload&lt;/a&gt; potesse fungere da &lt;strong&gt;polyfill per l&#39;attributo loading&lt;/strong&gt;, ispirandomi a sviluppare e rilasciare la versione 12 dello script, che introduce la nuova opzione &lt;code&gt;use_native&lt;/code&gt; per abilitare il lazy-loading nativo dove supportato. Puoi già usarlo oggi stesso.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://andreaverlicchi.eu/img/22t26E0XUI-648.webp 648w&quot; sizes=&quot;648px&quot;&gt;&lt;img alt=&quot;Usa caricamento nativo in vanilla lazyload&quot; loading=&quot;eager&quot; fetchpriority=&quot;high&quot; src=&quot;https://andreaverlicchi.eu/img/22t26E0XUI-648.png&quot; width=&quot;648&quot; height=&quot;339&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;h2 id=&quot;aspetta-cosa&quot; tabindex=&quot;-1&quot;&gt;Aspetta... cosa? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/native-lazy-loading-with-vanilla-lazyload/#aspetta-cosa&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Nel caso ti fossi perso l&#39;articolo di Addy Osmani, sarà possibile caricare le immagini e gli iframe in modalità lazy &lt;em&gt;nativamente&lt;/em&gt; tramite l&#39;attributo &lt;code&gt;loading=&amp;quot;lazy&amp;quot;&lt;/code&gt;, ed è già possibile farlo su Chrome 75 (attualmente Canary).&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;loading&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;...&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;iframe&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;loading&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;...&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;iframe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I browser scaricheranno inizialmente una piccolissima parte delle immagini (~2kb) per ottenere alcune informazioni iniziali (ad es. le dimensioni), per poi scaricare il resto quando stanno &lt;em&gt;per entrare nel viewport&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Il problema è che se assegni direttamente il &lt;code&gt;src&lt;/code&gt; (e/o &lt;code&gt;srcset&lt;/code&gt;) alle immagini, i browser che non supportano ancora il lazy loading nativo le scaricheranno tutte immediatamente, e questo è qualcosa che potresti voler evitare per risparmiare larghezza di banda e velocizzare il tuo sito o applicazione web.&lt;/p&gt;
&lt;p&gt;Per questo motivo, ho aggiunto l&#39;opzione &lt;code&gt;use_native&lt;/code&gt; nella versione 12 di &lt;em&gt;vanilla-lazyload&lt;/em&gt;, che abilita il lazy-loading nativo dove supportato.&lt;/p&gt;
&lt;p&gt;Maggiori informazioni sul lazy loading nativo possono essere trovate nel post di Addy Osmani &lt;a href=&quot;https://addyosmani.com/blog/lazy-loading/&quot;&gt;native image lazy-loading&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;il-browser-necessario&quot; tabindex=&quot;-1&quot;&gt;Il browser necessario &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/native-lazy-loading-with-vanilla-lazyload/#il-browser-necessario&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A partire dal 10 aprile 2019, il lazy loading nativo è nelle prime fasi (developer preview) ed è disponibile solo in Chrome 75 (attualmente Canary), e dietro un flag. Quindi per testarlo, devi:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://www.google.com/chrome/canary/&quot;&gt;Scarica Chrome Canary&lt;/a&gt; e installalo&lt;/li&gt;
&lt;li&gt;In Chrome Canary, vai all&#39;URL &lt;em&gt;chrome://flags&lt;/em&gt; e abilita i seguenti flag:
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Enable lazy image loading&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Enable lazy iframe loading&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Riavvia Chrome Canary&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;demo&quot; tabindex=&quot;-1&quot;&gt;Demo &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/native-lazy-loading-with-vanilla-lazyload/#demo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ora che hai il browser Chrome Canary con il lazy loading nativo abilitato, puoi iniziare visitando la seguente pagina demo.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://verlok.github.io/vanilla-lazyload/demos/native_lazyload_conditional.html&quot;&gt;Apri la demo&lt;/a&gt; &lt;em&gt;e/o&lt;/em&gt; &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/blob/master/demos/native_lazyload_conditional.html&quot;&gt;Controlla il codice&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Se hai fatto tutto correttamente, ecco cosa succederà:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Su Chrome 75 (Canary), LazyLoad attiverà il &lt;strong&gt;lazy-loading nativo&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Su altri browser e versioni precedenti di Chrome, verrà eseguito il &lt;strong&gt;lazy loading basato su JavaScript&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;provalo-sul-tuo-sito&quot; tabindex=&quot;-1&quot;&gt;Provalo sul tuo sito! &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/native-lazy-loading-with-vanilla-lazyload/#provalo-sul-tuo-sito&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Per provarlo tu stesso, devi seguire questi passaggi.&lt;/p&gt;
&lt;h3 id=&quot;markup&quot; tabindex=&quot;-1&quot;&gt;Markup &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/native-lazy-loading-with-vanilla-lazyload/#markup&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Per assicurarti che i tuoi utenti vedano le tue immagini il prima possibile, ti consiglio di caricare immediatamente le immagini in cima alla tua pagina web, solo quelle che sai che saranno posizionate &lt;em&gt;above-the-fold&lt;/em&gt; nei viewport più comuni, considerando smartphone, tablet e computer.&lt;/p&gt;
&lt;p&gt;Per farlo, le prime immagini nella pagina dovrebbero essere caricate usando normali tag &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;. Puoi usare l&#39;attributo &lt;code&gt;loading=&amp;quot;eager&amp;quot;&lt;/code&gt; per assicurarti che vengano caricate il prima possibile.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;eager-eagle.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;loading&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;eager&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Eager Eagle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tutte le altre immagini &lt;em&gt;below-the-fold&lt;/em&gt; dovrebbero invece essere caricate usando gli attributi &lt;code&gt;data-src&lt;/code&gt;, &lt;code&gt;data-srcset&lt;/code&gt; e &lt;code&gt;data-sizes&lt;/code&gt; al posto di &lt;code&gt;src&lt;/code&gt;, &lt;code&gt;srcset&lt;/code&gt; e &lt;code&gt;sizes&lt;/code&gt;, per evitare un caricamento immediato (eager) nei browser che non supportano &lt;code&gt;loading=&amp;quot;lazy&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy-sloth.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Lazy Sloth&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Link:&lt;/strong&gt; per una guida completa su come caricare in modo lazy le immagini responsive, leggi &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/native-lazy-loading-with-vanilla-lazyload/lazy-load-responsive-images-in-2019-srcset-sizes-more&quot;&gt;maggiori informazioni sul lazy loading delle immagini responsive&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;e-ora-passiamo-al-codice-javascript&quot; tabindex=&quot;-1&quot;&gt;E ora passiamo al codice Javascript! &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/native-lazy-loading-with-vanilla-lazyload/#e-ora-passiamo-al-codice-javascript&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Avrai bisogno della versione 12 di vanilla-lazyload.
&lt;br&gt;Puoi includerla tramite CDN:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cdn.jsdelivr.net/npm/vanilla-lazyload@12.0.0/dist/lazyload.min.js&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Oppure installarla tramite npm:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install vanilla-lazyload@12.0.0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nel tuo codice, imposta l&#39;opzione &lt;code&gt;use_native&lt;/code&gt; a &lt;code&gt;true&lt;/code&gt; quando istanzi LazyLoad:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LazyLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;elements_selector&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;.lazy&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;use_native&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Questo qui&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Il flag &lt;code&gt;use_native: true&lt;/code&gt; imposta questi comportamenti contestuali:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;dove il lazy loading nativo è supportato, LazyLoad aggiunge l&#39;attributo &lt;code&gt;loading=&amp;quot;lazy&amp;quot;&lt;/code&gt; alle immagini, quindi si limita a sostituire gli attributi &lt;code&gt;data-*&lt;/code&gt; con quelli corretti. A questo punto il browser gestirà il lazy loading da solo.&lt;/li&gt;
&lt;li&gt;dove il lazy loading nativo NON è supportato, il lazy loading continuerà a essere gestito da JavaScript, sfruttando l&#39;API IntersectionObserver del browser.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;per-concludere&quot; tabindex=&quot;-1&quot;&gt;Per concludere &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/native-lazy-loading-with-vanilla-lazyload/#per-concludere&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Caricare i contenuti in modalità lazy è molto importante per &lt;strong&gt;migliorare la velocità di caricamento di un sito web&lt;/strong&gt;; i produttori di browser stanno finalmente iniziando a implementarlo nativamente e non vedo l&#39;ora che sia disponibile su Edge, Safari e Firefox.&lt;/p&gt;
&lt;p&gt;Fino ad allora, puoi avere &lt;strong&gt;sia il lazy loading nativo che quello basato su JavaScript&lt;/strong&gt; usando &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload 12&lt;/a&gt;, semplicemente impostando l&#39;opzione &lt;code&gt;use_native&lt;/code&gt; a &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Provalo!&lt;/p&gt;
&lt;p&gt;Se ti piace, &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;metti una stella ⭐ alla repository&lt;/a&gt;. Se trovi qualcosa che non va, &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/issues&quot;&gt;apri una segnalazione (issue)&lt;/a&gt; in modo che io possa provare a risolverlo. Per qualsiasi domanda, &lt;a href=&quot;https://twitter.com/verlok&quot;&gt;contattami su Twitter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Un saluto!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Design di tabelle responsive e accessibili</title>
		<link href="https://andreaverlicchi.eu/it/blog/tables-look-like-lists-look-like-tables-accessible-responsive-design/"/>
		<updated>2019-03-08T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/tables-look-like-lists-look-like-tables-accessible-responsive-design/</id>
		<content type="html">&lt;p&gt;Come fare in modo che una tabella potenzialmente larga si adatti ai dispositivi più piccoli, senza perdere in leggibilità e accessibilità? Ecco alcune semplici soluzioni per far apparire le tabelle come liste e le liste come tabelle, all&#39;interno di un design responsive e accessibile.&lt;/p&gt;
&lt;p&gt;Ipotizziamo di avere una tabella HTML &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; contenente degli ordini, ognuno dei quali ha:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;un&#39;immagine&lt;/li&gt;
&lt;li&gt;una descrizione&lt;/li&gt;
&lt;li&gt;un prezzo&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;E abbiamo la necessità di far sì che:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;appaia come una lista&lt;/strong&gt; su viewport piccole, tipicamente gli smartphone&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;appaia come una tabella&lt;/strong&gt; su viewport più grandi, come tablet e computer&lt;/li&gt;
&lt;li&gt;sia &lt;strong&gt;accessibile&lt;/strong&gt; (vedi &lt;a href=&quot;https://www.w3.org/standards/webdesign/accessibility&quot;&gt;accessibilità&lt;/a&gt;), ad esempio per gli utenti non vedenti&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;il-markup-della-tabella&quot; tabindex=&quot;-1&quot;&gt;Il markup della tabella &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/tables-look-like-lists-look-like-tables-accessible-responsive-design/#il-markup-della-tabella&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ecco il markup della tabella di partenza.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;table&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;thead&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;th&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;scope&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;col&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Foto&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;th&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;th&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;scope&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;col&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Descrizione&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;th&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;th&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;scope&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;col&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Prezzo&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;th&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;thead&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tbody&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/70x100&amp;amp;text=Product&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Descrizione&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;EUR 12.345&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/70x100&amp;amp;text=Product&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Descrizione&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;EUR 12.345&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;td&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tbody&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;table&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;La soluzione in questo caso consiste nell&#39;impostare &lt;code&gt;display: flex&lt;/code&gt; sulle righe (&lt;code&gt;tr&lt;/code&gt;), e poi orientare le celle in verticale usando &lt;code&gt;flex-direction: column&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;tr&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; flex&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;flex-direction&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; column&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 400px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;tr&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;flex-direction&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; row&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;E boom. Ecco l&#39;esempio su CodePen.&lt;/p&gt;
&lt;iframe loading=&quot;lazy&quot; height=&quot;350&quot; style=&quot;width: 100%;&quot; scrolling=&quot;no&quot; title=&quot;Table markup, list layout (on small viewports)&quot; src=&quot;https://codepen.io/verlok/embed/GeWXGy/?height=350&amp;theme-id=light&amp;default-tab=html,result&quot; frameborder=&quot;no&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot;&gt;
  Vedi la Pen &lt;a href=&quot;https://codepen.io/verlok/pen/GeWXGy/&quot;&gt;Table markup, list layout (on small viewports)&lt;/a&gt; di Andrea Verlicchi
  (&lt;a href=&quot;https://codepen.io/verlok&quot;&gt;@verlok&lt;/a&gt;) su &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.
&lt;/iframe&gt;
&lt;h2 id=&quot;ma-si-tratta-davvero-di-una-tabella&quot; tabindex=&quot;-1&quot;&gt;Ma si tratta davvero di una tabella? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/tables-look-like-lists-look-like-tables-accessible-responsive-design/#ma-si-tratta-davvero-di-una-tabella&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il tag &lt;code&gt;table&lt;/code&gt; è davvero quello corretto da usare in questo caso? Non è che forse lo abbiamo scelto solo per comodità di layout? In fin dei conti, non si tratta semplicemente di una &lt;strong&gt;lista&lt;/strong&gt; di ordini? Allora perché non utilizzare invece un tag &lt;code&gt;ul&lt;/code&gt;?&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;photo&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/70x100&amp;amp;text=Product&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;description&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Descrizione&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;price&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;EUR 12.345&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;photo&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/70x100&amp;amp;text=Product&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;description&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Descrizione&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;price&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;EUR 12.345&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In questo caso, nel CSS, dobbiamo solo allineare orizzontalmente i &lt;code&gt;div&lt;/code&gt; all&#39;interno degli elementi della lista (&lt;code&gt;li&lt;/code&gt;), quando c&#39;è abbastanza spazio per farlo.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 400px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; flex&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ecco il risultato:&lt;/p&gt;
&lt;iframe loading=&quot;lazy&quot; height=&quot;350&quot; style=&quot;width: 100%;&quot; scrolling=&quot;no&quot; title=&quot;List markup, table layout (on large viewports)&quot; src=&quot;https://codepen.io/verlok/embed/pYeOwq/?height=350&amp;theme-id=light&amp;default-tab=html,result&quot; frameborder=&quot;no&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot;&gt;
  Vedi la Pen &lt;a href=&quot;https://codepen.io/verlok/pen/pYeOwq/&quot;&gt;List markup, table layout (on large viewports)&lt;/a&gt; di Andrea Verlicchi
  (&lt;a href=&quot;https://codepen.io/verlok&quot;&gt;@verlok&lt;/a&gt;) su &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.
&lt;/iframe&gt;
&lt;h2 id=&quot;considerazioni-sull-accessibilita&quot; tabindex=&quot;-1&quot;&gt;Considerazioni sull&#39;accessibilità &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/tables-look-like-lists-look-like-tables-accessible-responsive-design/#considerazioni-sull-accessibilita&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Le tabelle (&lt;code&gt;table&lt;/code&gt;) possono essere estremamente accessibili se &lt;a href=&quot;https://webaim.org/techniques/tables/data&quot;&gt;sviluppate correttamente&lt;/a&gt;, ma credo che abbia senso utilizzarle solo quando i dati in ogni singola cella hanno almeno 2 intestazioni (header): una all&#39;inizio della colonna e una all&#39;inizio della riga.&lt;/p&gt;
&lt;p&gt;Se hai solo un titolo per ogni colonna e poche colonne in totale, probabilmente è meglio considerarla come una lista e scriverne il markup di conseguenza, usando &lt;code&gt;ul&lt;/code&gt; o &lt;code&gt;ol&lt;/code&gt; a seconda delle preferenze. Assicurati di fare la scelta corretta!&lt;/p&gt;
&lt;p&gt;Infine, ma non meno importante: se utilizzi un markup non tabellare (&lt;code&gt;ul&lt;/code&gt;, &lt;code&gt;div&lt;/code&gt;, &lt;code&gt;span&lt;/code&gt;) che viene mostrato visivamente come una tabella e desideri renderlo accessibile, assicurati di utilizzare i &lt;a href=&quot;https://www.w3.org/TR/wai-aria-practices/examples/table/table.html&quot;&gt;ruoli ARIA (ARIA roles)&lt;/a&gt; per definire &lt;code&gt;rowgroup&lt;/code&gt;, &lt;code&gt;columnheader&lt;/code&gt;, &lt;code&gt;rowheader&lt;/code&gt;, &lt;code&gt;cell&lt;/code&gt;, ecc.&lt;/p&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/tables-look-like-lists-look-like-tables-accessible-responsive-design/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Puoi usare Flexbox per far sì che una tabella sembri una lista, o una lista sembri una tabella con grande facilità. Tieni sempre a mente l&#39;accessibilità! Quando sviluppi tabelle reali, usa gli header per righe e colonne. Quando sviluppi pseudo-tabelle, usa i ruoli ARIA per definire chi fa cosa.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Caricamento lazy di immagini responsive nel 2019</title>
		<link href="https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/"/>
		<updated>2019-03-01T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/</id>
		<content type="html">&lt;p&gt;Negli ultimi anni, sia per lavoro che come autore e manutentore di uno &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;script LazyLoad&lt;/a&gt;, mi sono specializzato nel &lt;strong&gt;lazy loading&lt;/strong&gt; (caricamento pigro) di &lt;strong&gt;immagini responsive&lt;/strong&gt;. Oggi ti mostrerò quale codice HTML, CSS e JavaScript devi scrivere &lt;em&gt;nel 2019&lt;/em&gt; per servire immagini responsive &lt;em&gt;e&lt;/em&gt; caricarle in modalità lazy. Nella seconda parte del post, ti mostrerò anche come fare in modo che il browser &lt;strong&gt;scelga nativamente l&#39;immagine in formato WebP&lt;/strong&gt; quando lo supporta.&lt;/p&gt;
&lt;h2 id=&quot;articolo-obsoleto&quot; tabindex=&quot;-1&quot;&gt;Articolo obsoleto! 👀 &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#articolo-obsoleto&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Un momento! Stai leggendo una vecchia versione di questo articolo.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;👉 &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp&quot;&gt;Leggi l&#39;&lt;strong&gt;aggiornamento del 2020&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;lazy-responsive-cosa&quot; tabindex=&quot;-1&quot;&gt;Lazy responsive... cosa? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#lazy-responsive-cosa&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Le &lt;strong&gt;immagini responsive&lt;/strong&gt; sono le immagini che si adattano allo schermo dell&#39;utente &lt;em&gt;e al contempo&lt;/em&gt; mantengono veloci i nostri siti web scaricando solo la sorgente corretta per la specifica &lt;strong&gt;larghezza della viewport&lt;/strong&gt; (dai piccoli dispositivi mobili ai grandi computer desktop), considerando anche la &lt;strong&gt;densità dello schermo&lt;/strong&gt; dell&#39;utente (display retina, hiDPI, ecc.).&lt;/p&gt;
&lt;p&gt;Il &lt;strong&gt;lazy loading delle immagini&lt;/strong&gt; è una tecnica per velocizzare il sito web &lt;strong&gt;evitando di caricare le immagini che si trovano sotto la piega (below the fold)&lt;/strong&gt;, caricandole poi &lt;strong&gt;solo quando entrano nella viewport&lt;/strong&gt;. Oltre alle prestazioni, questo ti consente anche di risparmiare larghezza di banda e denaro, ad esempio se paghi un servizio CDN a consumo per le immagini.&lt;/p&gt;
&lt;h2 id=&quot;ricevuto-ora-mostrami-un-po-di-codice&quot; tabindex=&quot;-1&quot;&gt;Ricevuto! Ora mostrami un po&#39; di codice! &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#ricevuto-ora-mostrami-un-po-di-codice&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;→ &lt;a href=&quot;http://verlok.github.io/vanilla-lazyload/demos/image_srcset_lazy_sizes.html&quot;&gt;Dai un&#39;occhiata ai risultati&lt;/a&gt; ← che otterrai. Apri gli &lt;strong&gt;strumenti per sviluppatori (developer tools)&lt;/strong&gt; del tuo browser e vai nel pannello &lt;strong&gt;Network&lt;/strong&gt;. Vedrai che le prime immagini vengono caricate immediatamente (in modalità &lt;em&gt;eager&lt;/em&gt;) all&#39;atterraggio sulla pagina, mentre le restanti vengono caricate via via che &lt;strong&gt;scorri verso il basso&lt;/strong&gt; del documento.&lt;/p&gt;
&lt;h3 id=&quot;il-markup-html&quot; tabindex=&quot;-1&quot;&gt;Il markup HTML &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#il-markup-html&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Ecco il markup di un&#39;immagine responsive caricata immediatamente.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Immagine responsive caricata immediatamente --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Image 01&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=Img+01&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
		https://via.placeholder.com/220x280?text=Img+01 220w,
		https://via.placeholder.com/440x560?text=Img+01 440w
	&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Per assicurarti che i tuoi utenti vedano le immagini &lt;strong&gt;il prima possibile&lt;/strong&gt;, ti consiglio di &lt;strong&gt;caricare immediatamente le immagini in cima&lt;/strong&gt; alla pagina web, ovvero solo quelle che si troveranno &lt;em&gt;sopra la piega (above the fold)&lt;/em&gt; nelle viewport più comuni, considerando smartphone, tablet e computer.&lt;/p&gt;
&lt;p&gt;Ricorda sempre che il lazy loading è un&#39;operazione gestita tramite JavaScript, quindi prima che il download di qualsiasi immagine lazy &lt;strong&gt;possa iniziare&lt;/strong&gt;, il codice JavaScript deve essere &lt;strong&gt;scaricato, interpretato ed eseguito&lt;/strong&gt;, le immagini lazy devono essere &lt;strong&gt;individuate nel DOM&lt;/strong&gt; e &lt;strong&gt;la loro posizione valutata&lt;/strong&gt;. E tutte queste operazioni richiedono del tempo.&lt;/p&gt;
&lt;p&gt;Ed ecco il markup di cui avrai bisogno per caricare un&#39;immagine responsive in modalità &lt;em&gt;lazy&lt;/em&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Immagine responsive caricata in modalità lazy --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Image 03&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=Img+03&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=Img+03 220w,
        https://via.placeholder.com/440x560?text=Img+03 440w&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;data-sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Se vuoi che le tue immagini lazy abbiano un&#39;anteprima a bassa risoluzione durante il caricamento, puoi inserire una piccola immagine a bassa qualità nel tag &lt;code&gt;src&lt;/code&gt; in questo modo:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Immagine responsive in modalità lazy con anteprima a bassa qualità --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Image 03&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/11x14?text=Img+03&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=Img+03&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/220x280?text=Img+03 220w,
        https://via.placeholder.com/440x560?text=Img+03 440w&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;data-sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Stiamo usando il tag HTML &lt;code&gt;img&lt;/code&gt; e non il tag &lt;code&gt;picture&lt;/code&gt;, poiché quest&#39;ultimo non è necessario in questo caso. Approfondirò i casi d&#39;uso del tag &lt;code&gt;picture&lt;/code&gt; &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#casi-d-uso-del-tag-picture&quot;&gt;più in basso&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Ma aspetta, e per quanto riguarda Internet Explorer?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;È vero, Internet Explorer non supporta le immagini responsive, ma dato che è rimasta in circolazione solo la sua ultima versione e sta lentamente scomparendo dai nostri radar (nei siti che gestiamo, la sua quota si aggira intorno al 4%), ti suggerisco di NON utilizzare un polyfill per le immagini responsive, affidandoti invece semplicemente all&#39;immagine specificata nell&#39;attributo &lt;code&gt;src&lt;/code&gt; (o &lt;code&gt;data-src&lt;/code&gt;).&lt;/p&gt;
&lt;h3 id=&quot;inclusione-dello-script&quot; tabindex=&quot;-1&quot;&gt;Inclusione dello script &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#inclusione-dello-script&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Per caricare le immagini lazy quando entrano nella viewport, hai bisogno di uno script di lazy load come &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt;, uno script leggero come l&#39;aria (1,9 kb gzipped), configurabile ed SEO-friendly che sviluppo e miglioro dal 2014. È basato sull&#39;API del browser &lt;code&gt;IntersectionObserver&lt;/code&gt;, quindi è velocissimo e garantisce uno scorrimento fluido (jank-free) anche sui dispositivi meno potenti.&lt;/p&gt;
&lt;p&gt;Ecco il modo più semplice per includere lo script nella tua pagina.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cdn.jsdelivr.net/npm/vanilla-lazyload@11.0.4/dist/lazyload.min.js&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Altri modi per includere LazyLoad nelle tue pagine web, ad esempio utilizzando uno script &lt;code&gt;async&lt;/code&gt; con auto-inizializzazione, usando RequireJS, Webpack o Rollup, sono &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/#include-lazyload-in-your-project&quot;&gt;documentati qui&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;inizializzazione-di-lazyload&quot; tabindex=&quot;-1&quot;&gt;Inizializzazione di LazyLoad &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#inizializzazione-di-lazyload&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Devi fare in modo che LazyLoad gestisca e carichi tutte le immagini con la classe &lt;code&gt;.lazy&lt;/code&gt; nella pagina. Puoi inizializzare &lt;code&gt;LazyLoad&lt;/code&gt; in questo modo:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; lazyLoad &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LazyLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;elements_selector&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;.lazy&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;// Altre opzioni qui&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;alcuni-trucchi-css&quot; tabindex=&quot;-1&quot;&gt;Alcuni trucchi CSS &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#alcuni-trucchi-css&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Ci sono anche alcune funzionalità che puoi ottenere utilizzando esclusivamente i CSS. Devi:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Fare in modo che le immagini lazy non ancora caricate occupino dello spazio&lt;/strong&gt;. Se non lo fai, tali immagini avranno altezza &lt;code&gt;0&lt;/code&gt; e collasseranno una accanto all&#39;altra. Di conseguenza, entreranno nella viewport tutte nello stesso momento, vanificando i nostri sforzi per caricarle man mano che compaiono sullo schermo.&lt;/li&gt;
&lt;li&gt;Evitare che le immagini vuote appaiano come interrotte (broken images)&lt;/li&gt;
&lt;li&gt;Risolvere un&#39;anomalia di Firefox che mostra l&#39;icona dell&#39;immagine non trovata durante il caricamento delle immagini&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Puoi fare tutto questo usando queste regole CSS:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/*
Fa in modo che il contenitore delle immagini occupi spazio
quando le immagini non sono ancora caricate.
Questo valore dipende dal tuo layout.
*/&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.imageList li&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;min-height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 300px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/*
Evita che le immagini vuote appaiano come interrotte
*/&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;img:not([src]):not([srcset])&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;visibility&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/*
Risolve l&#39;anomalia di Firefox durante il caricamento delle immagini
*/&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@-moz-document&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;url-prefix&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;img:-moz-loading&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;visibility&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;casi-d-uso-del-tag-picture&quot; tabindex=&quot;-1&quot;&gt;Casi d&#39;uso del tag picture &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#casi-d-uso-del-tag-picture&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Finora ho parlato del tag &lt;code&gt;img&lt;/code&gt; con gli attributi &lt;code&gt;srcset&lt;/code&gt; e &lt;code&gt;sizes&lt;/code&gt;, che rappresenta la soluzione per la stragrande maggioranza delle immagini responsive di cui potresti aver bisogno su un sito o un&#39;applicazione web. Ora, in quali casi dovresti usare invece il tag &lt;code&gt;picture&lt;/code&gt;?&lt;/p&gt;
&lt;h3 id=&quot;proporzioni-width-height-ratio-differenti&quot; tabindex=&quot;-1&quot;&gt;Proporzioni (width/height ratio) differenti &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#proporzioni-width-height-ratio-differenti&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Caso d&#39;uso: devi mostrare immagini con &lt;strong&gt;proporzioni (aspect ratio) differenti&lt;/strong&gt; a seconda di una media query. Ad esempio, vuoi mostrare immagini verticali (&lt;em&gt;portrait&lt;/em&gt;) sui dispositivi mobili e immagini orizzontali (&lt;em&gt;landscape&lt;/em&gt;) su viewport più ampie, come tablet e computer.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;http://verlok.github.io/vanilla-lazyload/demos/picture_media.html&quot;&gt;Dai un&#39;occhiata ai risultati&lt;/a&gt; ←&lt;/p&gt;
&lt;p&gt;Ecco il codice di cui avrai bisogno in questo caso. Per avere immagini caricate immediatamente, ti basterà usare gli attributi standard &lt;code&gt;src&lt;/code&gt; e &lt;code&gt;srcset&lt;/code&gt; senza il prefisso &lt;code&gt;data-&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: 1024px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/1024x576?text=Horizontal+Image 1x,
      https://via.placeholder.com/2048x1152?text=Horizontal+Image 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(max-width: 1023px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/640x960?text=Vertical+Image 1x,
      https://via.placeholder.com/1280x1920?text=Vertical+Image 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Stivaletti&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/1024x576?text=Horizontal+Image&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;passaggio-automatico-al-formato-webp&quot; tabindex=&quot;-1&quot;&gt;Passaggio automatico al formato WebP &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#passaggio-automatico-al-formato-webp&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Caso d&#39;uso: vuoi che le immagini &lt;strong&gt;passino automaticamente al formato WebP&lt;/strong&gt; se il browser supporta tale formato.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;http://verlok.github.io/vanilla-lazyload/demos/picture_type_webp.html&quot;&gt;Dai un&#39;occhiata ai risultati&lt;/a&gt; ←&lt;/p&gt;
&lt;p&gt;Ecco il codice! Anche in questo caso, per caricare le immagini immediatamente, usa semplicemente gli attributi standard &lt;code&gt;src&lt;/code&gt;, &lt;code&gt;srcset&lt;/code&gt; e &lt;code&gt;sizes&lt;/code&gt; senza il prefisso &lt;code&gt;data-&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image/webp&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/1024x576?text=WebP+Image 1x,
      https://via.placeholder.com/2048x1152?text=WebP+Image 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/256.jpg?text=1024x576+Jpg+Image&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://via.placeholder.com/1024x576?text=Jpg+Image 1x,
      https://via.placeholder.com/2048x1152?text=Jpg+Image 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;data-sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;220px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;An image&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;lazy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;un-ultima-cosa&quot; tabindex=&quot;-1&quot;&gt;&lt;em&gt;Un&#39;ultima cosa&lt;/em&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#un-ultima-cosa&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Lo script vanilla &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;LazyLoad&lt;/a&gt; sfrutta l&#39;API &lt;code&gt;IntersectionObserver&lt;/code&gt;, pertanto sui browser che non la supportano (come Internet Explorer e le vecchie versioni di Safari) caricherà tutte le immagini subito al momento dell&#39;esecuzione, portando all&#39;incirca allo stesso risultato che si otterrebbe senza usare alcun lazy loader.&lt;/p&gt;
&lt;p&gt;Se vuoi caricare i tuoi contenuti in modalità lazy sul 100% dei browser in circolazione (io non lo farei, ma la scelta spetta a te), devi includere lo script &lt;a href=&quot;https://github.com/w3c/IntersectionObserver/tree/master/polyfill&quot;&gt;IntersectionObserver Polyfill&lt;/a&gt; prima di LazyLoad.&lt;/p&gt;
&lt;p&gt;Puoi inserire lo script nella pagina subito prima di quello di LazyLoad, in questo modo...&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cdn.jsdelivr.net/npm/intersection-observer@0.5.1/intersection-observer.js&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cdn.jsdelivr.net/npm/vanilla-lazyload@11.0.4/dist/lazyload.min.js&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;...oppure puoi caricare il polyfill come dipendenza di LazyLoad utilizzando &lt;em&gt;RequireJS&lt;/em&gt; o un altro caricatore di moduli AMD. &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/blob/master/README.md#include-via-requirejs-without-intersectionobserver-polyfill&quot;&gt;Maggiori informazioni qui&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusioni&quot; tabindex=&quot;-1&quot;&gt;Conclusioni &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#conclusioni&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ecco un riassunto dei punti chiave:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Non caricare tutte le immagini in modalità lazy, ma solo quelle &lt;em&gt;below the fold&lt;/em&gt; (sotto la piega)&lt;/li&gt;
&lt;li&gt;Utilizza il tag &lt;code&gt;img&lt;/code&gt; per le immagini responsive semplici&lt;/li&gt;
&lt;li&gt;Utilizza il tag &lt;code&gt;picture&lt;/code&gt; per servire in modo condizionale la versione WebP delle immagini o per modificarne le proporzioni (aspect ratio)&lt;/li&gt;
&lt;li&gt;Utilizza &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/&quot;&gt;vanilla-lazyload&lt;/a&gt; per caricare le immagini lazy&lt;/li&gt;
&lt;li&gt;Utilizza opzionalmente il polyfill per IntersectionObserver se vuoi abilitare il lazy loading sul 100% dei browser&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Se qualcosa non fosse chiaro o potesse essere migliorato, ti invito a &lt;a href=&quot;https://andreaverlicchi.eu/contact/&quot;&gt;contattarmi&lt;/a&gt; per farmelo sapere.&lt;/p&gt;
&lt;p&gt;Se hai trovato utile questo post, non esitare a condividerlo!&lt;/p&gt;
&lt;h3 id=&quot;risorse-utili&quot; tabindex=&quot;-1&quot;&gt;Risorse utili &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-in-2019-srcset-sizes-more/#risorse-utili&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://alistapart.com/article/responsive-images-in-practice&quot;&gt;Responsive images in practice&lt;/a&gt; @ A List Apart (in inglese)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images&quot;&gt;Responsive images&lt;/a&gt; @ Mozilla Developer Network (in inglese)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://css-tricks.com/responsive-images-css/&quot;&gt;Responsive images in CSS&lt;/a&gt; @ CSS Tricks (in inglese)&lt;/li&gt;
&lt;li&gt;Sito web del &lt;a href=&quot;https://responsiveimages.org&quot;&gt;Responsive images community group&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
	</entry>
	
	<entry>
		<title>Verificare se un elemento è ancora nella viewport dopo un certo tempo</title>
		<link href="https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/"/>
		<updated>2018-08-27T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/</id>
		<content type="html">&lt;p&gt;Cosa faresti se qualcuno ti chiedesse di caricare un elemento DOM solo se &lt;strong&gt;rimane all&#39;interno della viewport per un determinato periodo di tempo&lt;/strong&gt;? Utilizzeresti &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt;, vero? 😉 Questa è esattamente la nuova funzionalità che la community di GitHub ha richiesto per LazyLoad, allo scopo di &lt;strong&gt;evitare il caricamento di elementi che gli utenti hanno saltato&lt;/strong&gt; scorrendo via velocemente. In questo post vorrei condividere con te la soluzione.&lt;/p&gt;
&lt;p&gt;Ci sono un paio di modi per farlo. Il primo consiste nel controllare la posizione dell&#39;elemento nel tempo, il secondo sfrutta &lt;code&gt;IntersectionObserver&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;il-metodo-lento-senza-intersectionobserver&quot; tabindex=&quot;-1&quot;&gt;Il metodo (lento) senza IntersectionObserver &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#il-metodo-lento-senza-intersectionobserver&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Questo metodo è molto più lento rispetto all&#39;utilizzo di &lt;code&gt;IntersectionObserver&lt;/code&gt; perché comporta:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;il monitoraggio degli eventi &lt;code&gt;scroll&lt;/code&gt; e &lt;code&gt;resize&lt;/code&gt; del browser per chiamare una callback (gestita con throttling)&lt;/li&gt;
&lt;li&gt;all&#39;interno della callback, un ciclo su tutti gli elementi osservati per chiamare una funzione &lt;code&gt;isInsideViewport&lt;/code&gt; che verifichi se sono nella viewport&lt;/li&gt;
&lt;li&gt;la funzione &lt;code&gt;isInsideViewport&lt;/code&gt; a sua volta controlla una &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/blob/support/8.x/src/lazyload.viewport.js&quot;&gt;serie di parametri&lt;/a&gt; come &lt;code&gt;getBoundingClientRect&lt;/code&gt; dell&#39;elemento, &lt;code&gt;innerHeight&lt;/code&gt; della finestra, &lt;code&gt;pageYOffset&lt;/code&gt;, ecc., e restituisce un valore booleano&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tutto questo solo per sapere quando gli elementi entrano nella viewport.&lt;/p&gt;
&lt;p&gt;Per sapere se un determinato elemento è rimasto nella viewport per un certo tempo, dovresti fare qualcosa del genere:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;quando l&#39;elemento entra nella viewport, avvii una funzione tramite &lt;code&gt;setTimeout&lt;/code&gt;. Chiamiamola &lt;code&gt;isStillInsideViewport&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;all&#39;interno di questa funzione, verifichi se l&#39;elemento è ancora nella viewport chiamando &lt;code&gt;isInsideViewport&lt;/code&gt; su quell&#39;elemento, quindi:
&lt;ul&gt;
&lt;li&gt;se lo è, lo carichi e lo rimuovi dagli elementi osservati&lt;/li&gt;
&lt;li&gt;se NON lo è, non lo carichi e continui a monitorarlo&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Un concetto piuttosto lineare, ma non così rapido da eseguire.&lt;/p&gt;
&lt;h2 id=&quot;il-metodo-con-intersectionobserver&quot; tabindex=&quot;-1&quot;&gt;Il metodo con IntersectionObserver &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#il-metodo-con-intersectionobserver&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Questo metodo è molto più veloce perché comporta unicamente quanto segue:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;configuri un &lt;code&gt;IntersectionObserver&lt;/code&gt; e lo usi per osservare tutti gli elementi da monitorare&lt;/li&gt;
&lt;li&gt;questo chiama una funzione &lt;code&gt;onIntersection&lt;/code&gt; ogni volta che un elemento si interseca con la viewport&lt;/li&gt;
&lt;li&gt;puoi gestire tutta la logica di caricamento all&#39;interno della funzione &lt;code&gt;onIntersection&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Non c&#39;è alcun bisogno di monitorare gli eventi &lt;code&gt;scroll&lt;/code&gt; o &lt;code&gt;resize&lt;/code&gt; del browser.&lt;/p&gt;
&lt;h3 id=&quot;prima-idea&quot; tabindex=&quot;-1&quot;&gt;Prima idea &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#prima-idea&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Il mio primo pensiero era di farlo senza &lt;code&gt;IntersectionObserver&lt;/code&gt;, il che significava dover verificare lo stato &amp;quot;è all&#39;interno della viewport&amp;quot; dopo un determinato timeout.&lt;/p&gt;
&lt;p&gt;Si è scoperto però che non esiste un modo elegante per verificare se un elemento si trova all&#39;interno della viewport usando &lt;code&gt;IntersectionObserver&lt;/code&gt;. Tutto ciò che si ottiene sono delle callback quando un elemento si interseca con la viewport.&lt;/p&gt;
&lt;h3 id=&quot;scoprire-i-threshold-soglie&quot; tabindex=&quot;-1&quot;&gt;Scoprire i threshold (soglie) &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#scoprire-i-threshold-soglie&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Ma aspetta, cos&#39;è quell&#39;opzione &lt;code&gt;thresholds&lt;/code&gt; di &lt;code&gt;IntersectionObserver&lt;/code&gt; menzionata nella &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API&quot;&gt;documentazione&lt;/a&gt;? 😲&lt;/p&gt;
&lt;p&gt;Dice MDN:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Un singolo numero o un array di numeri che indicano a quale percentuale di visibilità del target debba essere eseguita la callback dell&#39;observer. Se desideri rilevare solo quando la visibilità supera il 50%, puoi usare il valore 0.5. Se vuoi che la callback venga eseguita ogni volta che la visibilità supera un altro 25%, specificherai l&#39;array [0, 0.25, 0.5, 0.75, 1]. Il valore predefinito è 0 (ovvero, non appena anche un solo pixel è visibile, la callback viene eseguita). Un valore di 1.0 significa che la soglia non è considerata superata finché ogni singolo pixel non è visibile.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Dopo aver fatto qualche prova con questa opzione e aver testato il risultato in una specifica &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/blob/master/demos/delay_test.html&quot;&gt;demo di caricamento ritardato (delay load)&lt;/a&gt;, ho scoperto che passando &lt;code&gt;0&lt;/code&gt; all&#39;opzione &lt;code&gt;thresholds&lt;/code&gt; (che è il valore predefinito), la funzione &lt;code&gt;onIntersection&lt;/code&gt; viene chiamata anche quando l&#39;elemento &lt;em&gt;esce&lt;/em&gt; dalla viewport.&lt;/p&gt;
&lt;h3 id=&quot;la-soluzione-definitiva&quot; tabindex=&quot;-1&quot;&gt;La soluzione definitiva &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#la-soluzione-definitiva&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Una volta capito come intercettare quando un elemento &lt;strong&gt;esce dalla viewport&lt;/strong&gt;, risolvere il problema principale è diventato &lt;strong&gt;molto più semplice&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;La soluzione finale consiste nel:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;quando un elemento entra nella viewport, impostare un &lt;code&gt;setTimeout&lt;/code&gt; per caricare l&#39;elemento&lt;/li&gt;
&lt;li&gt;memorizzare ciascun ID del timeout in un attributo &lt;code&gt;data-&lt;/code&gt; dell&#39;elemento correlato&lt;/li&gt;
&lt;li&gt;lasciare che l&#39;elemento si carichi allo scadere del timeout&lt;/li&gt;
&lt;li&gt;se l&#39;elemento esce dalla viewport prima che il timeout venga eseguito, annullare il timeout tramite &lt;code&gt;clearTimeout&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Semplice e lineare! 😊&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;mostrami-il-codice&quot; tabindex=&quot;-1&quot;&gt;Mostrami il codice! &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#mostrami-il-codice&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Puoi trovare il codice completo nel file &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/blob/master/src/lazyload.js&quot;&gt;&lt;code&gt;lazyload.js&lt;/code&gt;&lt;/a&gt; di vanilla-lazyload e nei relativi import correlati. Se non ti va di saltare da un file all&#39;altro, puoi anche aprire il file pacchettizzato &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/blob/master/dist/lazyload.es2015.js&quot;&gt;&lt;code&gt;lazyload.es2015.js&lt;/code&gt;&lt;/a&gt; nella cartella &lt;code&gt;dist&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Di seguito è riportata una &lt;strong&gt;versione semplificata&lt;/strong&gt; del codice per comodità.&lt;/p&gt;
&lt;h3 id=&quot;configurazione-di-intersectionobserver&quot; tabindex=&quot;-1&quot;&gt;Configurazione di IntersectionObserver &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#configurazione-di-intersectionobserver&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; gObserver &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;IntersectionObserver&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;onIntersection&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;rootMargin&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;0px&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;threshold&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;L&#39;opzione &lt;code&gt;rootMargin&lt;/code&gt; impostata su &lt;code&gt;0px&lt;/code&gt; indica di osservare la dimensione effettiva della viewport. Puoi passare qualsiasi lunghezza CSS per espandere l&#39;area osservata. Ad esempio, passare &lt;code&gt;300px&lt;/code&gt; la espanderà di tale misura sopra, a destra, sotto e a sinistra.&lt;/p&gt;
&lt;h3 id=&quot;la-funzione-onintersection&quot; tabindex=&quot;-1&quot;&gt;La funzione onIntersection &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#la-funzione-onintersection&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Questa funzione viene chiamata ogni volta che si verifica un&#39;intersezione e il parametro rappresenta l&#39;insieme di elementi (entries) che si sono intersecati con la viewport.&lt;/p&gt;
&lt;p&gt;Ipotizzando che &lt;code&gt;watchedElements&lt;/code&gt; siano gli elementi monitorati dallo script (vedi sotto), dopo ogni intersezione essi dovrebbero essere rimossi dall&#39;elenco degli elementi già gestiti (caricati).&lt;/p&gt;
&lt;p&gt;La funzione &lt;code&gt;purgeElements&lt;/code&gt; esula dagli scopi di questo post, ma si limita a restituire un sottoinsieme di &lt;code&gt;watchedElements&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;onIntersection&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;entries&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  entries&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;manageIntersection&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  watchedElements &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;purgeElements&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;watchedElements&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;la-funzione-manageintersection&quot; tabindex=&quot;-1&quot;&gt;La funzione manageIntersection &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#la-funzione-manageintersection&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Questa funzione viene chiamata per ciascuna entry che si è intersecata con la viewport. Sia in entrata che in uscita.&lt;/p&gt;
&lt;p&gt;In entrata avvia il caricamento ritardato dell&#39;elemento. In uscita lo annulla.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;manageIntersection&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;entry&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; element &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; entry&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isIntersecting&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;entry&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;delayLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; delayTime&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;cancelDelayLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;funzione-di-utilita-isintersecting&quot; tabindex=&quot;-1&quot;&gt;Funzione di utilità isIntersecting &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#funzione-di-utilita-isintersecting&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Questa è una funzione di utilità per comprendere se un elemento si stia intersecando o meno con la viewport.&lt;/p&gt;
&lt;p&gt;Nota che:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;entry.isIntersecting&lt;/code&gt; necessita di un fallback perché è &lt;code&gt;null&lt;/code&gt; in alcune versioni di Microsoft Edge&lt;/li&gt;
&lt;li&gt;&lt;code&gt;entry.intersectionRatio&lt;/code&gt; da solo non è sufficiente poiché potrebbe essere &lt;code&gt;0&lt;/code&gt; su alcuni elementi in intersezione&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;isIntersecting&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt;
  entry&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;isIntersecting &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; entry&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;intersectionRatio &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;la-funzione-delayload&quot; tabindex=&quot;-1&quot;&gt;La funzione delayLoad &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#la-funzione-delayload&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Questa è la funzione che ritarda il caricamento dell&#39;elemento di un tempo pari a &lt;code&gt;delayTime&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;getTimeoutData&lt;/code&gt; e &lt;code&gt;setTimeoutData&lt;/code&gt; sono funzioni di utilità per leggere e scrivere l&#39;ID del timeout da/in un attributo data- dell&#39;elemento.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;delayLoad&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;element&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; delayTime&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; timeoutId &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getTimeoutData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;timeoutId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// il timeout era già impostato, non fa nulla&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  timeoutId &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;loadAndUnobserve&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;cancelDelayLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; delayTime&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;setTimeoutData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; timeoutId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;la-funzione-canceldelayload&quot; tabindex=&quot;-1&quot;&gt;La funzione cancelDelayLoad &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#la-funzione-canceldelayload&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Questa funzione ha il compito di annullare il timeout dell&#39;elemento, si impostato.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;cancelDelayLoad&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;element&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; timeoutId &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getTimeoutData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;timeoutId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// non fa nulla se il timeout non esiste&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;clearTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;timeoutId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;deleteTimeoutData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;la-funzione-loadandunobserve&quot; tabindex=&quot;-1&quot;&gt;La funzione loadAndUnobserve &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#la-funzione-loadandunobserve&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Questa funzione carica immediatamente l&#39;elemento e lo rimuove dagli elementi monitorati dall&#39;istanza di &lt;code&gt;IntersectionObserver&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;loadAndUnobserve&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Qui è dove fai effettivamente qualcosa con l&#39;elemento&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;revealElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  gObserver&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unobserve&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;al-mio-segnale-scatenate-l-inferno&quot; tabindex=&quot;-1&quot;&gt;Al mio segnale, scatenate l&#39;inferno! &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#al-mio-segnale-scatenate-l-inferno&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Abbiamo fatto tutto nel migliore dei modi finora, ma non abbiamo ancora avviato nulla! Abbiamo bisogno di un insieme di elementi da monitorare (&lt;code&gt;watchedElements&lt;/code&gt;) da passare al nostro &lt;code&gt;IntersectionObserver&lt;/code&gt;, altrimenti non succederà nulla.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; watchedElements &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;img&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
watchedElements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;element&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; gObserver&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;tutto-insieme&quot; tabindex=&quot;-1&quot;&gt;Tutto insieme &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#tutto-insieme&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Puoi trovare una versione funzionante del codice sopra indicato su CodeSandbox per poterci sperimentare direttamente!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://codesandbox.io/s/mzokk46vlx&quot;&gt;&lt;img src=&quot;https://codesandbox.io/static/img/play-codesandbox.svg&quot; alt=&quot;Verifica se un elemento è ancora nella viewport dopo un certo tempo&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;conclusioni&quot; tabindex=&quot;-1&quot;&gt;Conclusioni &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/#conclusioni&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Hai visto com&#39;è semplice verificare se un elemento è ancora nella viewport dopo un po&#39; di tempo usando &lt;code&gt;IntersectionObserver&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;Per ulteriori informazioni su come realizzare un LazyLoad utilizzando &lt;code&gt;IntersectionObserver&lt;/code&gt;, leggi &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/check-if-element-still-inside-viewport-after-given-time/using-intersection-observers-to-create-vanilla-lazyload&quot;&gt;Intersection Observer e caricamento lazy degli elementi&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;C&#39;è qualcosa che avresti fatto diversamente, o sei d&#39;accordo con le mie scelte? &lt;a href=&quot;https://andreaverlicchi.eu/contact/&quot;&gt;Contattami&lt;/a&gt; e fammi sapere cosa ne pensi!&lt;/p&gt;
&lt;p&gt;Se vuoi mostrare il tuo apprezzamento per LazyLoad, &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;lascia una stella su GitHub&lt;/a&gt;! ⭐&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Creare una libreria JavaScript con moduli ES2015, Gulp, Rollup e Jest</title>
		<link href="https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/"/>
		<updated>2017-09-09T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/</id>
		<content type="html">&lt;p&gt;Vediamo come scrivere una libreria JavaScript utilizzando &lt;a href=&quot;https://babeljs.io/learn-es2015/&quot;&gt;ES2015&lt;/a&gt; transpilato con &lt;a href=&quot;https://babeljs.io/&quot;&gt;Babel&lt;/a&gt;, sfruttando i &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import&quot;&gt;moduli ES&lt;/a&gt; impacchettati con &lt;a href=&quot;https://rollupjs.org/&quot;&gt;Rollup&lt;/a&gt; tramite &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/gulp.js&quot;&gt;Gulp&lt;/a&gt; e usando &lt;a href=&quot;https://facebook.github.io/jest/&quot;&gt;Jest&lt;/a&gt; per testare il codice.&lt;/p&gt;
&lt;p&gt;In questo articolo condivido l&#39;esperienza maturata durante lo sviluppo del mio script &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt;, poiché all&#39;epoca non riuscii a trovare nulla che spiegasse come utilizzare queste librerie insieme, in particolare &lt;strong&gt;Rollup e Jest&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;installare-gulp&quot; tabindex=&quot;-1&quot;&gt;Installare Gulp &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#installare-gulp&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Gulp è un &lt;strong&gt;task runner&lt;/strong&gt; simile a &lt;a href=&quot;https://gruntjs.com/&quot;&gt;Grunt&lt;/a&gt; per automatizzare i compiti più noiosi o lunghi nel flusso di lavoro di sviluppo. Ho scelto di migrare &lt;strong&gt;da Grunt a Gulp&lt;/strong&gt; perché quest&#39;ultimo è incredibilmente veloce, essendo basato sugli &lt;a href=&quot;https://medium.freecodecamp.org/node-js-streams-everything-you-need-to-know-c9141306be93&quot;&gt;stream (flussi di dati)&lt;/a&gt; di Node invece che sul file system.&lt;/p&gt;
&lt;p&gt;Per utilizzare Gulp, devi installarlo localmente nel tuo progetto, eseguendo:&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; --save-dev gulp&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Una buona opzione per utilizzare Gulp è installare il suo eseguibile da riga di comando tramite:&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-g&lt;/span&gt; gulp-cli&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Per maggiori informazioni, ti suggerisco di leggere l&#39;articolo &lt;a href=&quot;https://css-tricks.com/gulp-for-beginners/&quot;&gt;Gulp for beginners&lt;/a&gt; su CSS-Tricks (in inglese).&lt;/p&gt;
&lt;h2 id=&quot;configurare-gulp&quot; tabindex=&quot;-1&quot;&gt;Configurare Gulp &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#configurare-gulp&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;L&#39;esecuzione di Gulp richiede un file di configurazione chiamato &lt;code&gt;gulpfile.js&lt;/code&gt;. Per ora creane uno vuoto, ti mostrerò passo dopo passo cosa inserire al suo interno.&lt;/p&gt;
&lt;h3 id=&quot;1-analisi-statica-linting-dei-file-sorgente&quot; tabindex=&quot;-1&quot;&gt;1. Analisi statica (linting) dei file sorgente &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#1-analisi-statica-linting-dei-file-sorgente&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Essendo JavaScript un linguaggio dinamico e a tipizzazione debole, è particolarmente incline agli errori di sviluppo. Strumenti di linting come &lt;a href=&quot;https://eslint.org/&quot;&gt;ESLint&lt;/a&gt; consentono agli sviluppatori di individuare errori nel codice JavaScript senza doverlo effettivamente eseguire.&lt;/p&gt;
&lt;p&gt;Per installare ESLint per Gulp, basta eseguire:&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; --save-dev gulp-eslint&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quindi, nel tuo file &lt;code&gt;gulpfile.js&lt;/code&gt; vuoto, aggiungi:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; gulp &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;gulp&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; eslint &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;gulp-eslint&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;default&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    process&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;NODE_ENV&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;release&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;./src/**/*.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// ----------- linting --------------&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;eslint&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;eslint&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;eslint&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;failAfterError&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// --&gt; si interrompe in caso di errori&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// --&gt; concatena altre operazioni qui&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;NOTA: Impostare la variabile &lt;code&gt;process.env.NODE_ENV&lt;/code&gt; è necessario per farla coincidere con il task che stiamo eseguendo nella configurazione di Babel. Lo spiegherò &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#3-transpilazione-in-es5-con-babel&quot;&gt;tra poco&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;2-impacchettare-i-moduli-con-rollup&quot; tabindex=&quot;-1&quot;&gt;2. Impacchettare i moduli con Rollup &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#2-impacchettare-i-moduli-con-rollup&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Rollup è un module bundler per JavaScript che compila piccoli pezzi di codice in qualcosa di più grande, come una libreria. Utilizza il formato standard per i moduli di codice introdotto con la revisione ES2015 di JavaScript.&lt;/p&gt;
&lt;p&gt;In parole povere, Rollup legge il tuo file JavaScript principale e genera automaticamente un unico file più grande contenente tutti i moduli inclusi.&lt;/p&gt;
&lt;p&gt;Installa Rollup con:&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; --save-dev gulp-rollup gulp-rename&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quindi nel tuo gulpfile, aggiungi semplicemente un comando &lt;code&gt;.pipe()&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// ----------- rollup --------------&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rollup&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;umd&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;moduleName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;LazyLoad&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;./src/lazyload.js&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Questo indica a Rollup che deve produrre un modulo di tipo &lt;code&gt;umd&lt;/code&gt;, il cui nome sarà &lt;code&gt;LazyLoad&lt;/code&gt;, e che il punto di ingresso (entry point) da cui iniziare a cercare le dipendenze è &lt;code&gt;./src/lazyload.js&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Poiché voglio distribuire una versione dello script che non sia transpilata in ES5, la salvo come &lt;code&gt;lazyload.es2015.js&lt;/code&gt; concatenando i comandi &lt;code&gt;rename&lt;/code&gt; e &lt;code&gt;dest&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rename&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;lazyload.es2015.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;destFolder&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// --&gt; scrittura del bundle Rollup&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;destFolder&lt;/code&gt; è una variabile JavaScript ed è impostata su &lt;code&gt;./dist&lt;/code&gt; all&#39;interno del nostro &lt;code&gt;gulpfile.js&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;NOTA: &lt;a href=&quot;https://webpack.github.io/&quot;&gt;Webpack&lt;/a&gt; è uno strumento di bundling simile che potrebbe essere preferibile per applicazioni complesse, ma ho notato che il codice finale generato da Webpack è molto più pesante, perciò nel mio caso Rollup si è rivelato la scelta migliore.&lt;/p&gt;
&lt;h3 id=&quot;3-transpilazione-in-es5-con-babel&quot; tabindex=&quot;-1&quot;&gt;3. Transpilazione in ES5 con Babel &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#3-transpilazione-in-es5-con-babel&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Fino a questo punto abbiamo unito tutti i nostri moduli in un unico file che funzionerà solo nei browser moderni. Naturalmente, vogliamo produrre anche un file leggibile da browser &lt;em&gt;meno moderni&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Per installare Babel e il suo preset per ES2015, più un plugin per trasformare &lt;code&gt;Object.assign()&lt;/code&gt; in ES5, esegui:&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; --save-dev babel-core gulp-babel babel-preset-es2015 babel-plugin-transform-object-assign&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quindi, per elaborare con Babel il file precedentemente creato con Rollup e salvarlo come &lt;code&gt;lazyload.js&lt;/code&gt;, richiediamo &lt;code&gt;gulp-babel&lt;/code&gt; e aggiungiamo il seguente passaggio nel nostro &lt;code&gt;gulpfile.js&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; babel &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;gulp-babel&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// ----------- babelizzazione --------------&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;babel&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rename&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;lazyload.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;destFolder&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// --&gt; scrittura del file js es5 transpilato con Babel&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;La configurazione di Babel deve essere memorizzata in un file &lt;code&gt;.babelrc&lt;/code&gt; esterno, che nel mio caso si presenta così:&lt;/p&gt;
&lt;pre class=&quot;language-json&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;ignore&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;token string&quot;&gt;&quot;node_modules/**&quot;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;env&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token property&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;presets&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
                &lt;span class=&quot;token string&quot;&gt;&quot;es2015&quot;&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;plugins&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;transform-object-assign&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token property&quot;&gt;&quot;release&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;presets&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;es2015&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;token property&quot;&gt;&quot;modules&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;sourceMap&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token property&quot;&gt;&quot;plugins&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;transform-object-assign&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Avrai notato che ho configurato i due ambienti (&lt;code&gt;env&lt;/code&gt;) in modo diverso:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;release&lt;/code&gt; è quello utilizzato da Rollup in Gulp. Ricordi? Lo abbiamo impostato nel &lt;code&gt;gulpfile.js&lt;/code&gt; usando &lt;code&gt;process.env.NODE_ENV = &amp;quot;release&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;test&lt;/code&gt; è quello utilizzato da Jest (la spiegazione segue sotto)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;4-minificazione-con-uglify&quot; tabindex=&quot;-1&quot;&gt;4. Minificazione con Uglify &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#4-minificazione-con-uglify&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/mishoo/UglifyJS2&quot;&gt;Uglify JS&lt;/a&gt; è un set di strumenti per la compressione di JavaScript comunemente utilizzato per minificare la versione di distribuzione delle librerie JavaScript.&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; --save-dev gulp-uglify&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quindi, aggiungi il require e il pipe seguenti al nostro &lt;code&gt;gulpfile.js&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; uglify &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;gulp-uglify&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// ----------- minificazione --------------&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;uglify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rename&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;lazyload.min.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;destFolder&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// --&gt; scrittura del codice minificato&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;tutto-insieme&quot; tabindex=&quot;-1&quot;&gt;Tutto insieme &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#tutto-insieme&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Ecco come dovrebbe apparire il tuo file &lt;code&gt;gulpfile.js&lt;/code&gt; completo:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; gulp &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;gulp&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; eslint &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;gulp-eslint&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; rollup &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;gulp-rollup&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; rename &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;gulp-rename&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; babel &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;gulp-babel&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; uglify &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;gulp-uglify&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; destFolder &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;./dist&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;default&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    process&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;NODE_ENV&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;release&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;./src/**/*.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// ----------- linting --------------&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;eslint&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;eslint&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;eslint&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;failAfterError&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// --&gt; si interrompe in caso di errori&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// ----------- rollup --------------&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rollup&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token literal-property property&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;umd&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token literal-property property&quot;&gt;moduleName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;LazyLoad&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token literal-property property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;./src/lazyload.js&quot;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rename&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;lazyload.es2015.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;destFolder&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// --&gt; scrittura del bundle Rollup&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// ----------- babelizzazione --------------&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;babel&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rename&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;lazyload.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;destFolder&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// --&gt; scrittura del file ES5 transpilato con Babel&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// ----------- minificazione --------------&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;uglify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rename&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;lazyload.min.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;destFolder&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// --&gt; scrittura del codice minificato&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;watch&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    gulp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;./src/**/*.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;default&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Altri watcher&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;La sezione &lt;code&gt;&amp;quot;watch&amp;quot;&lt;/code&gt; fa sì che se eseguiamo il comando &lt;code&gt;gulp watch&lt;/code&gt;, &lt;code&gt;gulp&lt;/code&gt; monitora la cartella &lt;code&gt;src&lt;/code&gt; in cerca di modifiche e ricrea automaticamente i file nella cartella &lt;code&gt;dist&lt;/code&gt;. Comodo!&lt;/p&gt;
&lt;h2 id=&quot;eseguire-gulp&quot; tabindex=&quot;-1&quot;&gt;Eseguire Gulp &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#eseguire-gulp&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ora puoi compilare la tua libreria eseguendo Gulp in un&#39;unica soluzione:&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;gulp&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Oppure puoi fare in modo che monitori le modifiche ai file sorgente in &lt;code&gt;src&lt;/code&gt; mentre stai sviluppando:&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;gulp &lt;span class=&quot;token function&quot;&gt;watch&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;far-funzionare-jest-insieme-a-rollup&quot; tabindex=&quot;-1&quot;&gt;Far funzionare Jest insieme a Rollup &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#far-funzionare-jest-insieme-a-rollup&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Scriverò un altro post dettagliato su come ho usato Jest per testare moduli che diventano variabili e funzioni private minificate, ma il punto cruciale qui è come far convivere Jest e Rollup, dato che i due richiedono configurazioni di Babel differenti.&lt;/p&gt;
&lt;p&gt;Come abbiamo visto, la configurazione di Babel è suddivisa in due ambienti (&lt;code&gt;env&lt;/code&gt;) e quello impostato e utilizzato da Jest è &lt;code&gt;test&lt;/code&gt;. Questo perché Jest ha solo bisogno che l&#39;oggetto &lt;code&gt;presets&lt;/code&gt; contenga &lt;code&gt;[&amp;quot;es2015&amp;quot;]&lt;/code&gt;, mentre Rollup richiede &lt;code&gt;[&amp;quot;es2015&amp;quot;, {&amp;quot;modules&amp;quot;: false}]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Se hai seguito correttamente le spiegazioni, Jest dovrebbe funzionare fin da subito.&lt;/p&gt;
&lt;pre class=&quot;language-sh&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; --save-dev jest
&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-g&lt;/span&gt; jest-cli&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quindi lancia Jest così:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;jest
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Trovi maggiori informazioni su Jest nella pagina di &lt;a href=&quot;https://facebook.github.io/jest/docs/en/getting-started.html&quot;&gt;guida all&#39;avvio&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;passaggi-successivi&quot; tabindex=&quot;-1&quot;&gt;Passaggi successivi &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/create-a-javascript-library-using-es2015-modules-gulp-rollup-jest/#passaggi-successivi&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Una configurazione più avanzata consisterebbe nel configurare &lt;code&gt;npm&lt;/code&gt; come interfaccia a riga di comando per compilazione e test, in modo da poter eseguire &lt;code&gt;npm run build&lt;/code&gt; e &lt;code&gt;npm run test&lt;/code&gt; per lanciare la build o i test, o meglio ancora includere il processo di test nella build stessa in modo che se i test falliscono, fallisca anche la build. Questo sarà il mio prossimo passo.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Intersection Observer e il caricamento lazy degli elementi</title>
		<link href="https://andreaverlicchi.eu/it/blog/using-intersection-observers-to-create-vanilla-lazyload/"/>
		<updated>2017-09-04T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/using-intersection-observers-to-create-vanilla-lazyload/</id>
		<content type="html">&lt;p&gt;Ad agosto 2017 una nuova ed entusiasmante API del browser ha finalmente &lt;a href=&quot;https://hacks.mozilla.org/2017/08/intersection-observer-comes-to-firefox/&quot;&gt;ottenuto&lt;/a&gt; un &lt;a href=&quot;https://caniuse.com/#search=IntersectionObserver&quot;&gt;supporto piuttosto ampio&lt;/a&gt;: l&#39;&lt;strong&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API&quot;&gt;Intersection Observer API&lt;/a&gt;&lt;/strong&gt;, che possiamo utilizzare per rilevare quando due elementi DOM si intersecano, o quando un determinato elemento DOM &lt;strong&gt;entra nella viewport del browser&lt;/strong&gt;. Il caricamento lazy (pigro) delle immagini è proprio il caso d&#39;uso ideale.&lt;/p&gt;
&lt;p&gt;Circa 3 anni e 500 commit fa, ho dato vita a un nuovo &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;script per il caricamento lazy&lt;/a&gt; in vanilla JavaScript, attualmente noto come &lt;code&gt;vanilla-lazyload&lt;/code&gt; su &lt;a href=&quot;https://www.npmjs.com/package/vanilla-lazyload&quot;&gt;npm&lt;/a&gt; e &lt;a href=&quot;https://cdnjs.com/libraries/vanilla-lazyload&quot;&gt;cdnjs&lt;/a&gt;, che ha ricevuto oltre &lt;strong&gt;1.135 stelle su GitHub&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;il-passaggio-a-intersection-observer&quot; tabindex=&quot;-1&quot;&gt;Il passaggio a Intersection Observer &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-intersection-observers-to-create-vanilla-lazyload/#il-passaggio-a-intersection-observer&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Con la crescita della community organizzata attorno al mio script, &lt;a href=&quot;https://github.com/si14&quot;&gt;alcuni&lt;/a&gt; &lt;a href=&quot;https://github.com/ricardobrandao&quot;&gt;membri&lt;/a&gt; hanno richiesto il supporto all&#39;API Intersection Observer, tra &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/issues?q=label%3Aenhancement+is%3Aclosed&quot;&gt;altri miglioramenti&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Così ho deciso di accontentare i fan dello script. Il codice sorgente risultante è &lt;strong&gt;più piccolo del 40%&lt;/strong&gt; e vanilla-lazyload è ora &lt;strong&gt;molto più veloce&lt;/strong&gt; rispetto alla versione precedente. (a proposito, se conosci un modo per misurare con precisione le prestazioni di uno script, lascia pure un commento!)&lt;/p&gt;
&lt;h2 id=&quot;come-creare-un-intersection-observer&quot; tabindex=&quot;-1&quot;&gt;Come creare un Intersection Observer &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-intersection-observers-to-create-vanilla-lazyload/#come-creare-un-intersection-observer&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;L&#39;implementazione è piuttosto semplice: si crea una nuova istanza di &lt;code&gt;IntersectionObserver&lt;/code&gt; specificando &lt;strong&gt;una funzione di callback&lt;/strong&gt; da chiamare ogni volta che si verifica un evento di intersezione, e un paio di opzioni: &lt;strong&gt;root&lt;/strong&gt; e &lt;strong&gt;rootMargin&lt;/strong&gt;, ovvero:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;root&lt;/code&gt;: l&#39;elemento rispetto al quale si desidera &lt;strong&gt;verificare l&#39;intersezione&lt;/strong&gt; (&lt;code&gt;null&lt;/code&gt; indica la viewport del browser)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;rootMargin&lt;/code&gt;: utile nel caso in cui si voglia &lt;strong&gt;espandere o ridurre&lt;/strong&gt; l&#39;area sensibile dell&#39;elemento &lt;code&gt;root&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; myObserver &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;IntersectionObserver&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;entries&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;/* fai qualcosa */&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;rootMargin&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;300px 0&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Una volta creato l&#39;intersection observer e assegnato a una variabile, puoi iniziare a osservare un elemento target in questo modo:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; elementToObserve &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;observeMe&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
myObserver&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;elementToObserve&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;creare-l-observer&quot; tabindex=&quot;-1&quot;&gt;Creare l&#39;observer &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-intersection-observers-to-create-vanilla-lazyload/#creare-l-observer&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Dovendo verificare l&#39;intersezione di un insieme di immagini/elementi &lt;strong&gt;rispetto al contenitore in scorrimento&lt;/strong&gt; (la viewport o qualsiasi elemento con stile &lt;code&gt;overflow: scroll&lt;/code&gt;), ho creato un nuovo &lt;code&gt;IntersectionObserver&lt;/code&gt; memorizzandolo nella proprietà &lt;code&gt;_observer&lt;/code&gt; di LazyLoad.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;_observer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;IntersectionObserver&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;onIntersection&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; settings&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;container &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; document &lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; settings&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;container&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;rootMargin&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; settings&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;threshold &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;px&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;onIntersection&lt;/code&gt; è una funzione, illustrata di seguito&lt;/li&gt;
&lt;li&gt;&lt;code&gt;settings.container&lt;/code&gt; è il contenitore con lo scorrimento, il cui valore predefinito è &lt;code&gt;document&lt;/code&gt;, passato dall&#39;utente di LazyLoad nell&#39;oggetto delle opzioni&lt;/li&gt;
&lt;li&gt;&lt;code&gt;settings.threshold&lt;/code&gt; è il numero di pixel oltre il contenitore di scorrimento da cui iniziare a caricare le immagini/elementi (default &lt;code&gt;300&lt;/code&gt;px)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;la-funzione-onintersection&quot; tabindex=&quot;-1&quot;&gt;La funzione onIntersection &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-intersection-observers-to-create-vanilla-lazyload/#la-funzione-onintersection&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il punto cardine è che ogni volta che un elemento DOM si interseca con il contenitore di scorrimento, viene chiamata la funzione &lt;code&gt;onIntersection&lt;/code&gt;. Ecco come è definita:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;onIntersection&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;entries&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    entries&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;entry&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;isIntersecting&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; element &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; entry&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;revealElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; settings&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;_observer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unobserve&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Al parametro &lt;code&gt;entries&lt;/code&gt; vengono passati &lt;strong&gt;tutti gli elementi osservati&lt;/strong&gt; dall&#39;observer che invoca la funzione. Dobbiamo quindi &lt;strong&gt;ciclare su ogni elemento (entry)&lt;/strong&gt; e verificare se &lt;strong&gt;si sta intersecando&lt;/strong&gt; o meno con l&#39;elemento &lt;code&gt;root&lt;/code&gt;. Fortunatamente, la proprietà &lt;code&gt;isIntersecting&lt;/code&gt; fa proprio questo:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;se l&#39;elemento non si interseca, lo ignoriamo semplicemente eseguendo un &lt;code&gt;return&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;se l&#39;elemento si interseca, &lt;strong&gt;avviamo il caricamento della sorgente dell&#39;elemento&lt;/strong&gt; invocando &lt;code&gt;revealElement&lt;/code&gt;, e poi &lt;strong&gt;smettiamo di osservare questa specifica entry&lt;/strong&gt; (tramite &lt;code&gt;unobserve&lt;/code&gt;), dato che il caricamento è già iniziato e non c&#39;è più bisogno di tenerlo d&#39;occhio&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;osservare-un-elemento&quot; tabindex=&quot;-1&quot;&gt;Osservare un elemento &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-intersection-observers-to-create-vanilla-lazyload/#osservare-un-elemento&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Non manca qualcosa? Certo! Il codice spiegato finora non produce alcun effetto se non &lt;strong&gt;diciamo al nostro observer di monitorare un elemento&lt;/strong&gt; (o più di uno, nel nostro caso). Quello che dobbiamo fare è:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;_elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;element&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;_observer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Dove &lt;code&gt;this._elements&lt;/code&gt; è l&#39;insieme di elementi che LazyLoad ha individuato all&#39;interno di &lt;code&gt;this._container&lt;/code&gt; tramite un selettore specifico, al netto di quelli già commessi o elaborati (per gestire scenari come lo &lt;em&gt;scroll infinito&lt;/em&gt; o altri casi di aggiornamento del DOM).&lt;/p&gt;
&lt;h2 id=&quot;fallback&quot; tabindex=&quot;-1&quot;&gt;Fallback &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-intersection-observers-to-create-vanilla-lazyload/#fallback&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Poiché &lt;em&gt;non tutti i browser sono creati uguali&lt;/em&gt;, dobbiamo verificare il supporto a &lt;code&gt;IntersectionObserver&lt;/code&gt; prima di poterlo utilizzare. Il modo per farlo è semplice:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;IntersectionObserver&quot;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; window&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nel mio caso, sui browser in cui &lt;code&gt;IntersectionObserver&lt;/code&gt; non è supportato, LazyLoad caricherà &lt;strong&gt;tutte le immagini contemporaneamente&lt;/strong&gt;. Di conseguenza, se hai la necessità di caricare moltissime immagini e il tuo pubblico utilizza in percentuale significativa browser più datati, ti consiglio di utilizzare una versione di LazyLoad precedente alla 9. Consulta il &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload/blob/master/CHANGELOG.md&quot;&gt;changelog&lt;/a&gt; per maggiori dettagli.&lt;/p&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-intersection-observers-to-create-vanilla-lazyload/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Tutto qui! Intersection Observer rende il codice molto più compatto, veloce e leggibile. Se non lo stai già usando, dovresti assolutamente iniziare a provarlo.&lt;/p&gt;
&lt;p&gt;E non dimenticare: se hai una pagina molto lunga piena di immagini e altri contenuti, dovresti caricarli in modalità lazy utilizzando uno script dedicato, e la scelta migliore è sicuramente &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;vanilla-lazyload&lt;/a&gt;!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Usare le variabili CSS come unità di spaziatura</title>
		<link href="https://andreaverlicchi.eu/it/blog/using-css-variables-to-scale-layout-spaces/"/>
		<updated>2017-06-14T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/using-css-variables-to-scale-layout-spaces/</id>
		<content type="html">&lt;p&gt;In questo articolo ti mostro come puoi utilizzare le variabili CSS, note popolarmente come &lt;em&gt;proprietà personalizzate&lt;/em&gt; (CSS custom properties), per &lt;strong&gt;scalare gli spazi del tuo layout&lt;/strong&gt; su diverse media query.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Il vantaggio: file CSS più corti, leggeri e facili da mantenere.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Per dimostrarlo, ho creato su CodePen l&#39;esempio &lt;a href=&quot;https://codepen.io/verlok/pen/owzLPm?editors=1100&quot;&gt;CSS vars based layout spacing&lt;/a&gt;. Lo trovi incorporato alla fine di questo post.&lt;/p&gt;
&lt;h2 id=&quot;cosa-sono-le-variabili-css&quot; tabindex=&quot;-1&quot;&gt;Cosa sono le variabili CSS &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-css-variables-to-scale-layout-spaces/#cosa-sono-le-variabili-css&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Le variabili CSS sono una delle prossime grandi novità dei CSS. Non sono ancora &lt;a href=&quot;http://caniuse.com/#feat=css-variables&quot;&gt;supportate universalmente&lt;/a&gt; (spoiler: manca Internet Explorer) considerando le quote di mercato attuali dei browser, ma è giunto il momento di iniziare a sperimentarle, non trovi? Potrebbero rivelarsi utili nello sviluppo del tuo prossimo fantastico progetto!&lt;/p&gt;
&lt;p&gt;La potenza delle variabili CSS risiede nel fatto che possiamo assegnare un valore a un nome e fare riferimento a quel valore usando il suo nome.&lt;/p&gt;
&lt;h2 id=&quot;come-definire-una-variabile-css&quot; tabindex=&quot;-1&quot;&gt;Come definire una variabile CSS &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-css-variables-to-scale-layout-spaces/#come-definire-una-variabile-css&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Le variabili CSS possono essere definite in qualsiasi punto e vengono ereditate da tutti gli elementi figli dell&#39;elemento DOM a cui vengono applicate.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;--base-spacing&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 15px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Qui abbiamo definito una variabile CSS chiamata &lt;code&gt;--base-spacing&lt;/code&gt; e le abbiamo assegnato il valore &lt;code&gt;15px&lt;/code&gt;. La variabile è definita sull&#39;elemento &lt;code&gt;html&lt;/code&gt;, quindi sarà disponibile in tutto il nostro documento.&lt;/p&gt;
&lt;p&gt;(Sì, le variabili CSS devono iniziare con un doppio trattino (&lt;code&gt;--&lt;/code&gt;), il che è un po&#39; brutto, ma porta pazienza!)&lt;/p&gt;
&lt;h2 id=&quot;differenza-con-le-variabili-sass&quot; tabindex=&quot;-1&quot;&gt;Differenza con le variabili SASS &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-css-variables-to-scale-layout-spaces/#differenza-con-le-variabili-sass&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Nel caso tu stia pensando: &amp;quot;E con ciò? Uso già SASS e il mio file &lt;code&gt;_variables.scss&lt;/code&gt; è pieno zeppo di variabili!&amp;quot; - Beh, non è proprio la stessa cosa.&lt;/p&gt;
&lt;p&gt;Le variabili SASS vengono pre-elaborate, quindi vengono trasformate in un valore CSS fisso e statico. Quando il CSS viene caricato, &lt;strong&gt;la variabile va perduta&lt;/strong&gt; e rimane solo il suo valore, distribuito in tutti i punti in cui è stata utilizzata.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Una variabile SASS non può essere modificata dopo che il CSS è stato caricato. Le variabili CSS, invece, possono essere modificate tramite media query, JavaScript o tramite gli strumenti di sviluppo (developer tools) del tuo browser preferito.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;come-utilizzare-una-variabile-css&quot; tabindex=&quot;-1&quot;&gt;Come utilizzare una variabile CSS &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-css-variables-to-scale-layout-spaces/#come-utilizzare-una-variabile-css&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Vogliamo che la variabile &lt;code&gt;--base-spacing&lt;/code&gt; funga da unità di spaziatura da utilizzare per padding e margini in tutta la nostra pagina. Come procediamo?&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.box&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;--base-spacing&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;--base-spacing&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;h1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;--base-spacing&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Fantastico! Ora stiamo usando la nostra variabile CSS come unità di spaziatura, proprio come faremmo con una variabile SASS, ma... ora possiamo modificarla!&lt;/p&gt;
&lt;h2 id=&quot;modificare-il-valore-delle-variabili-css&quot; tabindex=&quot;-1&quot;&gt;Modificare il valore delle variabili CSS &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-css-variables-to-scale-layout-spaces/#modificare-il-valore-delle-variabili-css&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;È qui che avviene la magia. I valori delle variabili CSS possono essere riassegnati come faresti con qualsiasi altra proprietà CSS, utilizzando:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;le media query&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;i developer tools del tuo browser preferito&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;La prima cosa che puoi fare per comprendere la potenza delle variabili CSS è &lt;strong&gt;aprire i developer tools&lt;/strong&gt;, individuare la variabile nel file CSS e &lt;strong&gt;cambiarne il valore&lt;/strong&gt;. &lt;a href=&quot;https://codepen.io/verlok/pen/owzLPm?editors=1100&quot;&gt;Prova qui&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Nel nostro caso, vogliamo ampliare gli spazi sugli schermi più grandi, quindi ci basta fare così:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 500px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;--base-spacing&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 30px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tutto qui. Questa semplice riassegnazione della variabile farà scalare automaticamente tutti i nostri padding e margini, dato che abbiamo usato la variabile per definire i loro valori.&lt;/p&gt;
&lt;h2 id=&quot;demo&quot; tabindex=&quot;-1&quot;&gt;DEMO &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-css-variables-to-scale-layout-spaces/#demo&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ecco di cosa sto parlando:&lt;/p&gt;
&lt;p data-height=&quot;265&quot; data-theme-id=&quot;dark&quot; data-slug-hash=&quot;owzLPm&quot; data-default-tab=&quot;css,result&quot; data-user=&quot;verlok&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;CSS vars based layout spacing&quot; class=&quot;codepen&quot;&gt;Vedi la Pen &lt;a href=&quot;https://codepen.io/verlok/pen/owzLPm/&quot;&gt;CSS vars based layout spacing&lt;/a&gt; di Andrea Verlicchi (&lt;a href=&quot;https://codepen.io/verlok&quot;&gt;@verlok&lt;/a&gt;) su &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;script async=&quot;&quot; src=&quot;https://production-assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
&lt;h2 id=&quot;possibilita-infinite&quot; tabindex=&quot;-1&quot;&gt;Possibilità infinite &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/using-css-variables-to-scale-layout-spaces/#possibilita-infinite&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Ora che hai imparato a padroneggiare le variabili CSS, puoi spingerti ben oltre e lasciare che siano i tuoi utenti a decidere la spaziatura del layout, il colore principale o qualsiasi altra cosa.&lt;/p&gt;
&lt;p&gt;Ti bastano solo alcuni campi di input e poche righe di JavaScript, come dimostrato da &lt;a href=&quot;https://www.twitter.com/wesbos&quot;&gt;@wesbos&lt;/a&gt; in questo esempio.&lt;/p&gt;
&lt;p data-height=&quot;265&quot; data-theme-id=&quot;dark&quot; data-slug-hash=&quot;adQjoY&quot; data-default-tab=&quot;css,result&quot; data-user=&quot;wesbos&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Update CSS Variables with JS&quot; class=&quot;codepen&quot;&gt;Vedi la Pen &lt;a href=&quot;https://codepen.io/wesbos/pen/adQjoY/&quot;&gt;Update CSS Variables with JS&lt;/a&gt; di Wes Bos (&lt;a href=&quot;https://codepen.io/wesbos&quot;&gt;@wesbos&lt;/a&gt;) su &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;script async=&quot;&quot; src=&quot;https://production-assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
</content>
	</entry>
	
	<entry>
		<title>Cambiare il colore del testo per contrasto in base alla luminosità dello sfondo</title>
		<link href="https://andreaverlicchi.eu/it/blog/changing-text-color-for-contrast-based-on-background-lightness/"/>
		<updated>2017-06-02T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/changing-text-color-for-contrast-based-on-background-lightness/</id>
		<content type="html">&lt;p&gt;Se dovessi cambiare il colore di un testo in posizione fissa (&lt;code&gt;position: fixed&lt;/code&gt;) in base alla luminosità dello sfondo che scorre sotto di esso, come faresti? Filtri CSS, blend mode? E se dovessi supportare tutti i browser, incluso Internet Explorer? Ecco un paio di modi per farlo utilizzando le proprietà CSS &lt;code&gt;clip&lt;/code&gt; e &lt;code&gt;clip-path&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Ecco il risultato ottenuto con &lt;code&gt;clip&lt;/code&gt; - ampio supporto dei browser&lt;/p&gt;
&lt;iframe loading=&quot;lazy&quot; height=&quot;200&quot; scrolling=&quot;no&quot; title=&quot;Text color change at background using clip&quot; src=&quot;https://codepen.io/verlok/embed/VWZeBL/?height=194&amp;amp;theme-id=light&amp;amp;default-tab=result&amp;amp;embed-version=2&quot; frameborder=&quot;no&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; style=&quot;width: 100%;&quot;&gt;Vedi la Pen &lt;a href=&quot;https://codepen.io/verlok/pen/VWZeBL/&quot;&gt;Text color change at background using clip&lt;/a&gt; di Andrea Verlicchi (&lt;a href=&quot;https://codepen.io/verlok&quot;&gt;@verlok&lt;/a&gt;) su &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.
&lt;/iframe&gt;
&lt;p&gt;Ed ecco il risultato ottenuto con &lt;code&gt;clip-path&lt;/code&gt; - solo browser moderni&lt;/p&gt;
&lt;iframe loading=&quot;lazy&quot; height=&quot;200&quot; scrolling=&quot;no&quot; title=&quot;Text color change at background using clip-path&quot; src=&quot;https://codepen.io/verlok/embed/owvYjx/?height=265&amp;amp;theme-id=light&amp;amp;default-tab=result&amp;amp;embed-version=2&quot; frameborder=&quot;no&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;true&quot; style=&quot;width: 100%;&quot;&gt;Vedi la Pen &lt;a href=&quot;https://codepen.io/verlok/pen/owvYjx/&quot;&gt;Text color change at background using clip-path&lt;/a&gt; di Andrea Verlicchi (&lt;a href=&quot;https://codepen.io/verlok&quot;&gt;@verlok&lt;/a&gt;) su &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.
&lt;/iframe&gt;
&lt;p&gt;Cosa succede qui in pratica:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;il contenuto è avvolto da un box con classe &lt;code&gt;clipper&lt;/code&gt; che ne ritaglia il contenuto&lt;/li&gt;
&lt;li&gt;viene copiato all&#39;interno di ogni contenitore :(&lt;/li&gt;
&lt;li&gt;ha una posizione fissa tramite &lt;code&gt;position: fixed&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Dato che il contenuto ha una posizione fissa, rimane ancorato alla finestra del browser, ma viene ritagliato dagli elementi di ritaglio (clipping) che si muovono.&lt;/p&gt;
&lt;p&gt;Questa soluzione presenta tuttavia due problemi:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;c&#39;è un bug in IE ed Edge che rende invisibili i figli di tipo blocco del contenuto. Funziona però con gli elementi inline, anche se si tratta di un trucco (hack)&lt;/li&gt;
&lt;li&gt;dobbiamo copiare il contenuto all&#39;interno di ciascun contenitore&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ti viene in mente una soluzione migliore? Se sì, scrivila nei commenti!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Immagini responsive, uno standard HTML 5.1</title>
		<link href="https://andreaverlicchi.eu/it/blog/responsive-images-a-html-51-standard/"/>
		<updated>2017-04-10T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/responsive-images-a-html-51-standard/</id>
		<content type="html">&lt;p&gt;È ufficiale. Le immagini responsive sono una &lt;a href=&quot;https://www.w3.org/TR/html51/&quot;&gt;raccomandazione W3C&lt;/a&gt; da novembre 2016, caratterizzate dal nuovissimo tag &lt;code&gt;picture&lt;/code&gt; e dai nuovi attributi per il tag &lt;code&gt;img&lt;/code&gt;: &lt;code&gt;srcset&lt;/code&gt; e &lt;code&gt;sizes&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;perche-le-immagini-responsive&quot; tabindex=&quot;-1&quot;&gt;Perché le immagini responsive? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-a-html-51-standard/#perche-le-immagini-responsive&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Nel 2010, Ethan Marcotte ha iniziato a parlare di &lt;a href=&quot;https://alistapart.com/article/responsive-web-design&quot;&gt;responsive web design&lt;/a&gt;, un approccio al web design volto a consentire la visualizzazione delle pagine web in modo ottimale in base alle dimensioni della viewport del browser.&lt;/p&gt;
&lt;p&gt;È stato qualcosa di rivoluzionario, ma all&#39;improvviso noi sviluppatori ci siamo trovati di fronte a un nuovo problema: in un sito web responsive, &lt;strong&gt;quanto grandi dovrebbero essere i file delle immagini&lt;/strong&gt;?&lt;/p&gt;
&lt;p&gt;L&#39;approccio iniziale consisteva nell&#39;utilizzare un&#39;unica immagine di grandi dimensioni per tutte le larghezze di viewport, in modo che le immagini apparissero eccellenti sugli schermi grandi anche se venivano rimpicciolite sui dispositivi più piccoli. Ben presto, però, questa si è rivelata una cattiva pratica: le &lt;em&gt;connessioni più lente&lt;/em&gt; sui dispositivi mobili e le &lt;em&gt;CPU meno performanti&lt;/em&gt; rallentavano il sito web, peggiorando l&#39;esperienza dell&#39;utente.&lt;/p&gt;
&lt;p&gt;Gli sviluppatori hanno quindi iniziato a utilizzare JavaScript per &lt;em&gt;scegliere la dimensione corretta dell&#39;immagine&lt;/em&gt; in base alla viewport. È stato in quel periodo che sono nati script come &lt;a href=&quot;https://github.com/scottjehl/picturefill&quot;&gt;picturefill&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Il fatto è che JavaScript è più lento del puro HTML: deve essere scaricato, interpretato (parsed) ed eseguito prima ancora che il browser possa iniziare a scaricare le immagini. Il web aveva bisogno di qualcosa di nativo per tornare a definire le immagini direttamente nel codice HTML, consentendo ai browser di avviarne il download il prima possibile.&lt;/p&gt;
&lt;p&gt;Ecco perché un gruppo di designer e sviluppatori indipendenti, noto come &lt;a href=&quot;http://ricg.io/&quot;&gt;Responsive Images Community Group&lt;/a&gt;, ha iniziato a proporre nuovi tag e attributi.&lt;/p&gt;
&lt;h2 id=&quot;cosa-sono-le-immagini-responsive&quot; tabindex=&quot;-1&quot;&gt;Cosa sono le immagini responsive? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-a-html-51-standard/#cosa-sono-le-immagini-responsive&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&amp;quot;Immagini responsive&amp;quot; è il nome dato alla tecnica che consiste nel &lt;strong&gt;definire più sorgenti per ogni singola immagine&lt;/strong&gt;, facendo sì che i browser &lt;strong&gt;scarichino quella migliore&lt;/strong&gt; in base ai seguenti fattori:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;viewport del browser, o layout del tuo sito web&lt;/li&gt;
&lt;li&gt;densità di pixel del dispositivo&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Gli utenti hanno densità di pixel differenti a seconda dello schermo del loro dispositivo. I dispositivi standard hanno una densità di pixel pari a 1, il che significa che lo schermo ha 1 pixel fisico (device pixel) per ogni pixel CSS. I monitor HiDPI più recenti (inclusi i display &amp;quot;Retina&amp;quot;) hanno invece una densità maggiore. Ad esempio, una densità di pixel pari a 2 significa che lo schermo ha 2x2 pixel fisici per ciascun pixel CSS, e così via.&lt;/p&gt;
&lt;p&gt;I display HiDPI sono straordinari per il rendering di elementi vettoriali, come font o immagini SVG. Ma quando si tratta di renderizzare immagini bitmap, i browser si limitano a ingrandire l&#39;immagine originale, rendendola sfuocata su dispositivi che dovrebbero invece offrire una qualità superiore.&lt;/p&gt;
&lt;h2 id=&quot;supportare-i-display-hidpi&quot; tabindex=&quot;-1&quot;&gt;Supportare i display HiDPI &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-a-html-51-standard/#supportare-i-display-hidpi&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;La cosa più semplice che puoi fare con il nuovo attributo &lt;code&gt;srcset&lt;/code&gt; è supportare diverse densità di pixel. Ti basta specificare sorgenti diverse per la tua immagine, descrivendo ognuna con il descrittore &lt;code&gt;x&lt;/code&gt;, che indica la densità di pixel della sorgente dell&#39;immagine. In questo modo:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;shirt_300w.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;shirt_300w.jpg 1x, shirt_600w.jpg 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Una bella camicia&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;300&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;380&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In questo esempio, vogliamo mostrare un&#39;immagine di 300 x 380 pixel &lt;em&gt;CSS&lt;/em&gt;. L&#39;immagine a densità standard è &lt;code&gt;shirt_300w.jpg&lt;/code&gt; ed è descritta dal descrittore &lt;code&gt;1x&lt;/code&gt;. L&#39;immagine a doppia densità è &lt;code&gt;shirt_600w.jpg&lt;/code&gt;, e deve essere di 600 x 760 pixel.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nota:&lt;/strong&gt; i browser che comprendono il nuovo attributo &lt;code&gt;srcset&lt;/code&gt; ignoreranno l&#39;attributo &lt;code&gt;src&lt;/code&gt;, che è comunque richiesto come fallback.&lt;/p&gt;
&lt;p&gt;Questo è già un ottimo risultato per offrire la migliore qualità d&#39;immagine ai nostri utenti, ma cosa succede se nel nostro layout responsive la dimensione dell&#39;immagine varia a seconda dello spazio disponibile?&lt;/p&gt;
&lt;h2 id=&quot;dimensioni-dell-immagine-differenti&quot; tabindex=&quot;-1&quot;&gt;Dimensioni dell&#39;immagine differenti &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-a-html-51-standard/#dimensioni-dell-immagine-differenti&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Supponiamo che la nostra immagine debba avere le seguenti larghezze:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;300 pixel su viewport piccole (&amp;lt; 600)&lt;/li&gt;
&lt;li&gt;600 pixel su viewport medie (&amp;gt;= 600)&lt;/li&gt;
&lt;li&gt;1200 pixel su viewport grandi (&amp;gt;= 1200)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Come facciamo a garantire che i nostri utenti ottengano sempre la dimensione dell&#39;immagine che meglio si adatta alla loro viewport &lt;em&gt;e&lt;/em&gt; alla densità di pixel?&lt;/p&gt;
&lt;p&gt;Possiamo definire immagini con queste dimensioni:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Densità / Larghezza viewport&lt;/th&gt;
&lt;th&gt;&amp;lt; 600&lt;/th&gt;
&lt;th&gt;&amp;gt;= 600&lt;/th&gt;
&lt;th&gt;&amp;gt;= 1200&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1x&lt;/td&gt;
&lt;td&gt;300 x 380&lt;/td&gt;
&lt;td&gt;600 x 760&lt;/td&gt;
&lt;td&gt;1200 x 1520&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2x&lt;/td&gt;
&lt;td&gt;600 x 760&lt;/td&gt;
&lt;td&gt;1200 x 1520&lt;/td&gt;
&lt;td&gt;2400 x 3040&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Come puoi vedere, stiamo usando 4 diverse dimensioni di immagine. Ti consiglio di includere la larghezza nel nome del file dell&#39;immagine, poiché è molto più chiaro da comprendere.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;300 x 380 - shirt_300w.jpg&lt;/li&gt;
&lt;li&gt;600 x 760 - shirt_600w.jpg&lt;/li&gt;
&lt;li&gt;1200 x 1520 - shirt_1200w.jpg&lt;/li&gt;
&lt;li&gt;2400 x 3040 - shirt_2400w.jpg&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Per scrivere il relativo markup nel nostro codice HTML, dobbiamo fare così:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;shirt_300w.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
		shirt_300w.jpg   300w,
		shirt_600w.jpg   600w,
		shirt_1200w.jpg 1200w,
		shirt_2400w.jpg 2400w
	&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Una bella camicia&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: 1200px) 1200px,
         (min-width: 600px) 600px,
         300px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Con questo markup, the browser conosce lo spazio che l&#39;immagine occuperà sullo schermo (tramite &lt;code&gt;sizes&lt;/code&gt;) e tutte le sorgenti di immagini disponibili che abbiamo preparato per i nostri utenti (tramite &lt;code&gt;srcset&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;A questo punto, il browser sceglierà quale sorgente scaricare in base alle informazioni fornite e a quelle che conosce sull&#39;utente, come la densità dello schermo, i file in cache, la velocità di connessione, ecc.&lt;/p&gt;
&lt;h2 id=&quot;supporto-dei-browser&quot; tabindex=&quot;-1&quot;&gt;Supporto dei browser &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-a-html-51-standard/#supporto-dei-browser&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;L&#39;attributo &lt;code&gt;srcset&lt;/code&gt; è supportato da tutti i browser tranne Internet Explorer. Fortunatamente, esiste un &lt;a href=&quot;https://github.com/scottjehl/picturefill/&quot;&gt;polyfill&lt;/a&gt; ufficiale che possiamo utilizzare per emulare il comportamento nativo sui browser legacy.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Immagini responsive? Il tag picture non serve</title>
		<link href="https://andreaverlicchi.eu/it/blog/responsive-images-you-dont-need-picture-tag/"/>
		<updated>2015-12-21T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/responsive-images-you-dont-need-picture-tag/</id>
		<content type="html">&lt;p&gt;Supponiamo di avere un layout di sito web responsive in cui le immagini sono dimensionate al 100% del loro contenitore, ma &lt;strong&gt;il contenitore non è sempre largo quanto la viewport&lt;/strong&gt;. Dobbiamo per forza usare il tag &lt;code&gt;picture&lt;/code&gt; o il tag &lt;code&gt;img&lt;/code&gt; è sufficiente? &lt;strong&gt;Il tag &lt;code&gt;img&lt;/code&gt; è in grado di farlo da solo&lt;/strong&gt;, utilizzando i suoi attributi &lt;code&gt;sizes&lt;/code&gt; e &lt;code&gt;srcset&lt;/code&gt;. Ecco come.&lt;/p&gt;
&lt;h2 id=&quot;il-layout-delle-immagini&quot; tabindex=&quot;-1&quot;&gt;Il layout delle immagini &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-you-dont-need-picture-tag/#il-layout-delle-immagini&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Le immagini nel layout hanno le seguenti larghezze:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Larghezza Viewport&lt;/th&gt;
&lt;th&gt;Larghezza immagini&lt;/th&gt;
&lt;th&gt;Larghezza contenitore&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Da 0 a 767 px&lt;/td&gt;
&lt;td&gt;1/2 del contenitore&lt;/td&gt;
&lt;td&gt;100% senza padding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Da 768 px a 1023 px&lt;/td&gt;
&lt;td&gt;1/3 del contenitore&lt;/td&gt;
&lt;td&gt;100% con 30 px di padding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Da 1024 px a 1279 px&lt;/td&gt;
&lt;td&gt;1/4 del contenitore&lt;/td&gt;
&lt;td&gt;100% con 30 px di padding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Da 1280 px in su&lt;/td&gt;
&lt;td&gt;1/4 del contenitore&lt;/td&gt;
&lt;td&gt;1280 px con 30 px di padding&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;unita-utilizzabili-nell-attributo-sizes&quot; tabindex=&quot;-1&quot;&gt;Unità utilizzabili nell&#39;attributo &lt;code&gt;sizes&lt;/code&gt; &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-you-dont-need-picture-tag/#unita-utilizzabili-nell-attributo-sizes&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Quando usi il tag &lt;code&gt;img&lt;/code&gt;, nell&#39;attributo &lt;code&gt;sizes&lt;/code&gt; puoi specificare quanto larghe mostrare le tue immagini in base alle diverse media query. E puoi farlo non solo usando l&#39;unità di misura della larghezza della viewport (&lt;code&gt;vw&lt;/code&gt;), come spesso si legge in giro, ma &lt;strong&gt;utilizzando qualsiasi valore di lunghezza&lt;/strong&gt; e anche la funzione CSS &lt;strong&gt;&lt;code&gt;calc()&lt;/code&gt;&lt;/strong&gt;, utilissima quando si ha a che fare con padding o con la proprietà &lt;code&gt;max-width&lt;/code&gt; del contenitore.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Larghezza Viewport&lt;/th&gt;
&lt;th&gt;Larghezza immagini&lt;/th&gt;
&lt;th&gt;Larghezza contenitore&lt;/th&gt;
&lt;th&gt;Larghezza immagine in CSS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Da 0 a 767 px&lt;/td&gt;
&lt;td&gt;1/2 del contenitore&lt;/td&gt;
&lt;td&gt;100% senza padding&lt;/td&gt;
&lt;td&gt;&lt;code&gt;50vw&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Da 768 px a 1023 px&lt;/td&gt;
&lt;td&gt;1/3 del contenitore&lt;/td&gt;
&lt;td&gt;100% con 30 px di padding&lt;/td&gt;
&lt;td&gt;&lt;code&gt;calc(( 100vw - 60 px ) / 3)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Da 1024 px a 1279 px&lt;/td&gt;
&lt;td&gt;1/4 del contenitore&lt;/td&gt;
&lt;td&gt;100% con 30 px di padding&lt;/td&gt;
&lt;td&gt;&lt;code&gt;calc(( 100vw - 60 px ) / 4)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Da 1280 px in su&lt;/td&gt;
&lt;td&gt;1/4 del contenitore&lt;/td&gt;
&lt;td&gt;1280 px con 30 px di padding&lt;/td&gt;
&lt;td&gt;&lt;code&gt;305 px&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Vedi &lt;a href=&quot;https://codepen.io/verlok/pen/JGXeyz?editors=110&quot;&gt;questa pen su CodePen&lt;/a&gt; che utilizza le media query e i CSS per specificare le larghezze di &lt;code&gt;img&lt;/code&gt;, e &lt;a href=&quot;https://codepen.io/verlok/pen/adNQqX?editors=110&quot;&gt;quest&#39;altra pen&lt;/a&gt; che specifica l&#39;attributo &lt;code&gt;sizes&lt;/code&gt; direttamente all&#39;interno del tag &lt;code&gt;img&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Ti senti confuso? Se hai bisogno di una spiegazione più approfondita, leggi l&#39;articolo &lt;a href=&quot;https://ericportis.com/posts/2014/srcset-sizes/&quot;&gt;srcset and sizes&lt;/a&gt; di Eric Portis (in inglese), a mio parere il miglior articolo in assoluto sull&#39;uso di &lt;code&gt;img&lt;/code&gt; con &lt;code&gt;srcset&lt;/code&gt; e &lt;code&gt;sizes&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;calcolo-delle-dimensioni-delle-immagini-ottimizzate-in-base-a-spaziatura-dispositivo-e-orientamento&quot; tabindex=&quot;-1&quot;&gt;Calcolo delle dimensioni delle immagini ottimizzate in base a spaziatura, dispositivo e orientamento &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-you-dont-need-picture-tag/#calcolo-delle-dimensioni-delle-immagini-ottimizzate-in-base-a-spaziatura-dispositivo-e-orientamento&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Se vogliamo che le nostre immagini siano ottimizzate per le risoluzioni più comuni, dobbiamo:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Definire quali sono le risoluzioni e le densità di schermo più diffuse&lt;/li&gt;
&lt;li&gt;Decidere per quali risoluzioni/densità vogliamo ottimizzare&lt;/li&gt;
&lt;li&gt;Calcolare quali saranno le dimensioni delle immagini a queste risoluzioni/densità&lt;/li&gt;
&lt;li&gt;Ridimensionare le nostre immagini a quelle specifiche dimensioni&lt;/li&gt;
&lt;li&gt;Scrivere il markup delle &lt;code&gt;img&lt;/code&gt; nel codice HTML:
&lt;ol&gt;
&lt;li&gt;Elencare tutte le dimensioni delle immagini nell&#39;attributo &lt;code&gt;srcset&lt;/code&gt;, utilizzando il descrittore &lt;code&gt;w&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Elencare tutte le larghezze delle immagini nell&#39;attributo &lt;code&gt;sizes&lt;/code&gt;, come definito nella tabella precedente&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Per individuare le risoluzioni dello schermo e decidere quali ottimizzare, puoi utilizzare qualsiasi strumento come Google Analytics per raccogliere informazioni sui tuoi utenti e sui dispositivi che utilizzano maggiormente.&lt;/p&gt;
&lt;p&gt;Dopo alcuni &lt;a href=&quot;https://docs.google.com/spreadsheets/d/1BCeWGXOevUHlL8l9ti2i81C9BgSsHtybO9Z9WAYpfnQ/edit&quot;&gt;calcoli&lt;/a&gt;, le dimensioni delle immagini ottenute sono state le seguenti:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dispositivo e orientamento&lt;/th&gt;
&lt;th&gt;Largh. schermo&lt;/th&gt;
&lt;th&gt;Largh. img (css px)&lt;/th&gt;
&lt;th&gt;Altez. img (css px)&lt;/th&gt;
&lt;th&gt;Densità schermo&lt;/th&gt;
&lt;th&gt;Largh. img (px)&lt;/th&gt;
&lt;th&gt;Altez. img (px)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;iPhone 4/5/5s&lt;/td&gt;
&lt;td&gt;320&lt;/td&gt;
&lt;td&gt;160&lt;/td&gt;
&lt;td&gt;186&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;320&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;372&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;iPhone 6&lt;/td&gt;
&lt;td&gt;375&lt;/td&gt;
&lt;td&gt;187&lt;/td&gt;
&lt;td&gt;217&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;374&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;435&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;iPhone 5/5s in orizzontale&lt;/td&gt;
&lt;td&gt;568&lt;/td&gt;
&lt;td&gt;284&lt;/td&gt;
&lt;td&gt;330&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;568&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;660&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;iPhone 6 in orizzontale&lt;/td&gt;
&lt;td&gt;667&lt;/td&gt;
&lt;td&gt;333&lt;/td&gt;
&lt;td&gt;387&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;666&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;774&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;iPad / mini&lt;/td&gt;
&lt;td&gt;768&lt;/td&gt;
&lt;td&gt;236&lt;/td&gt;
&lt;td&gt;274&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;472&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;549&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;iPad / mini in orizzontale&lt;/td&gt;
&lt;td&gt;1024&lt;/td&gt;
&lt;td&gt;241&lt;/td&gt;
&lt;td&gt;280&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;482&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;560&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PC con larghezza da 1280px in su&lt;/td&gt;
&lt;td&gt;1280&lt;/td&gt;
&lt;td&gt;305&lt;/td&gt;
&lt;td&gt;355&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;305&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;355&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PC con larghezza 1280px e HiDPI&lt;/td&gt;
&lt;td&gt;1280&lt;/td&gt;
&lt;td&gt;305&lt;/td&gt;
&lt;td&gt;355&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;610&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;709&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PC con larghezza superiore a 1280px&lt;/td&gt;
&lt;td&gt;1920&lt;/td&gt;
&lt;td&gt;305&lt;/td&gt;
&lt;td&gt;355&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;305&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;355&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;passiamo-al-codice&quot; tabindex=&quot;-1&quot;&gt;Passiamo al codice! &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-you-dont-need-picture-tag/#passiamo-al-codice&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il codice del proof of concept (POC) che ho creato si trova su GitHub in &lt;a href=&quot;https://www.github.com/verlok/responsiveImagesTagsCompared&quot;&gt;questo repository&lt;/a&gt;, mentre la &lt;a href=&quot;http://verlok.github.io/responsiveImagesTagsCompared&quot;&gt;demo live è disponibile qui&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;markup-con-il-tag-picture&quot; tabindex=&quot;-1&quot;&gt;Markup con il tag picture &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-you-dont-need-picture-tag/#markup-con-il-tag-picture&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(max-width: 320px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://placehold.it/320x372 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(max-width: 375px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://placehold.it/374x435 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(max-width: 568px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://placehold.it/568x660 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(max-width: 667px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://placehold.it/666x774 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(max-width: 768px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://placehold.it/472x549 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(max-width: 1024px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://placehold.it/241x280 1x, http://placehold.it/482x560 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;source&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: 1280px)&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://placehold.it/305x355 1x, http://placehold.it/610x709 2x&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://placehold.it/305x355&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Immagine di un prodotto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;picture&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;markup-con-il-tag-img&quot; tabindex=&quot;-1&quot;&gt;Markup con il tag img &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-you-dont-need-picture-tag/#markup-con-il-tag-img&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://placehold.it/305x355&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
		http://placehold.it/241x280 241w,
		http://placehold.it/305x355 305w,
		http://placehold.it/320x372 320w,
		http://placehold.it/374x435 374w,
		http://placehold.it/472x549 472w,
		http://placehold.it/482x560 482w,
		http://placehold.it/568x660 578w,
		http://placehold.it/610x709 610w,
		http://placehold.it/666x774 666w
	&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: 1280px) 305px,
            (min-width: 1024px) calc((100vw - 60px) / 4),
            (min-width: 768px) calc((100vw - 60px) / 3),
            50vw&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Immagine di un prodotto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;conclusione&quot; tabindex=&quot;-1&quot;&gt;Conclusione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/responsive-images-you-dont-need-picture-tag/#conclusione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Il markup con &lt;code&gt;picture&lt;/code&gt; risulta essere molto più verboso, e non stiamo ancora supportando i display a densità singola sotto i 768px.&lt;/li&gt;
&lt;li&gt;Il markup con &lt;code&gt;img&lt;/code&gt; è più breve, meno ripetitivo e lascia che sia il browser a calcolare quale sia l&#39;immagine migliore da caricare in base alla risoluzione E alla densità di pixel.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Non hai bisogno del tag &lt;code&gt;picture&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Il motivo è che utilizzando il tag &lt;code&gt;img&lt;/code&gt; dovrai scrivere &lt;strong&gt;molto meno codice&lt;/strong&gt; per supportare &lt;strong&gt;molti più dispositivi e densità di schermo&lt;/strong&gt;. Grazie alla possibilità di utilizzare la funzione CSS &lt;code&gt;calc()&lt;/code&gt; all&#39;interno dell&#39;attributo &lt;code&gt;sizes&lt;/code&gt;, possiamo effettuare calcoli complessi per stabilire l&#39;immagine corretta da caricare anche in layout elaborati.&lt;/p&gt;
&lt;p&gt;Nota bene: i tag &lt;code&gt;picture&lt;/code&gt; e &lt;code&gt;img&lt;/code&gt; sono paragonabili solo quando tutte le immagini mantengono le &lt;strong&gt;stesse proporzioni (aspect ratio) su tutte le media query&lt;/strong&gt;. Se le proporzioni dell&#39;immagine devono cambiare per adattarsi a quelle del dispositivo, il tag &lt;code&gt;picture&lt;/code&gt; rimane l&#39;unica strada percorribile.&lt;/p&gt;
&lt;p&gt;Ciao!&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Caricamento lazy di immagini responsive con srcset e LazyLoad</title>
		<link href="https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/"/>
		<updated>2015-04-20T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/</id>
		<content type="html">&lt;p&gt;Ora è possibile (sì, oggi stesso!) implementare il &lt;strong&gt;lazy loading&lt;/strong&gt; (caricamento pigro) sulle &lt;strong&gt;immagini responsive&lt;/strong&gt;, così da far sì che si adattino agli schermi degli utenti &lt;em&gt;e&lt;/em&gt; mantenere veloce il nostro sito web. Evviva! &#92;o/ In questo articolo vedremo quale markup dobbiamo scrivere e quali librerie JavaScript saranno necessarie per farlo.&lt;/p&gt;
&lt;h2 id=&quot;articolo-obsoleto&quot; tabindex=&quot;-1&quot;&gt;Articolo obsoleto! 👀 &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/#articolo-obsoleto&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Un momento! Stai leggendo una vecchia versione di questo articolo.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;👉 &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/lazy-load-responsive-images-in-2020-srcset-sizes-picture-webp&quot;&gt;Leggi l&#39;&lt;strong&gt;aggiornamento del 2020&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;lazy-responsive-cosa&quot; tabindex=&quot;-1&quot;&gt;Lazy responsive... cosa? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/#lazy-responsive-cosa&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Le &lt;strong&gt;immagini responsive&lt;/strong&gt; sono una tecnica che permette alle immagini del tuo sito web di adattarsi alla &lt;strong&gt;larghezza della viewport&lt;/strong&gt; e alla &lt;strong&gt;densità dello schermo&lt;/strong&gt; (1x, 2x - display retina, ecc.). Per capire come fare, puoi leggere &lt;a href=&quot;http://alistapart.com/article/responsive-images-in-practice&quot;&gt;Responsive images in practice&lt;/a&gt; (in inglese) e puoi trovare ulteriori informazioni sul &lt;a href=&quot;http://responsiveimages.org/&quot;&gt;sito web del responsive images community group&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Il &lt;strong&gt;lazy loading delle immagini&lt;/strong&gt; è una tecnica per velocizzare il sito web &lt;strong&gt;evitando di caricare le immagini&lt;/strong&gt; che l&#39;utente potrebbe non vedere mai nella sua viewport, per poi &lt;strong&gt;caricarle solo quando vi fanno ingresso&lt;/strong&gt;. Oltre alle prestazioni, questo ti permette anche di risparmiare larghezza di banda (e denaro, se utilizzi un servizio CDN a consumo per le tue immagini).&lt;/p&gt;
&lt;h2 id=&quot;implementazione&quot; tabindex=&quot;-1&quot;&gt;Implementazione &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/#implementazione&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;http://verlok.github.io/img_srcset_lazyload&quot;&gt;Dai un&#39;occhiata ai risultati&lt;/a&gt; che otterremo combinando queste tecniche.&lt;/p&gt;
&lt;p&gt;Se apri il pannello Network dell&#39;inspector del browser, noterai che le prime immagini vengono caricate &amp;quot;normalmente&amp;quot; dal browser al caricamento della pagina, mentre le altre vengono caricate via via che scorri verso il basso del documento.&lt;/p&gt;
&lt;h3 id=&quot;il-markup&quot; tabindex=&quot;-1&quot;&gt;Il markup &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/#il-markup&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Ecco il markup di cui avrai bisogno per caricare in modalità lazy un&#39;immagine responsive.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Immagine caricata normalmente dal browser --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;
		img/41494516WM_10r_n_f.jpg 668w,
		img/41494516WM_10_n_f.jpg  334w,
		img/41494516WM_9r_n_f.jpg  446w,
		img/41494516WM_9_n_f.jpg   223w
	&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: 361px) 50vw,
        (min-width: 481px) 33.333vw,
        (min-width: 769px) 25vw,
        (min-width: 1025px) 20vw,
        100vw&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Immagine caricata in modalità lazy tramite JavaScript --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;data-srcset&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;img/41494516WM_10r_n_f.jpg 668w,
        img/41494516WM_10_n_f.jpg 334w,
        img/41494516WM_9r_n_f.jpg 446w,
        img/41494516WM_9_n_f.jpg 223w&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token attr-name&quot;&gt;sizes&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;(min-width: 361px) 50vw,
        (min-width: 481px) 33.333vw,
        (min-width: 769px) 25vw,
        (min-width: 1025px) 20vw,
        100vw&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nota che stiamo usando il tag HTML &lt;code&gt;img&lt;/code&gt; e &lt;strong&gt;non&lt;/strong&gt; &lt;code&gt;picture&lt;/code&gt;. Quest&#39;ultimo non è necessario perché in questo caso non stiamo modificando le proporzioni (ratio) dell&#39;immagine.&lt;/p&gt;
&lt;h3 id=&quot;inclusione-degli-script&quot; tabindex=&quot;-1&quot;&gt;Inclusione degli script &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/#inclusione-degli-script&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Prima di tutto, abbiamo bisogno di una libreria per caricare le immagini lazy quando entrano nella viewport. Esistono diverse librerie per il caricamento lazy delle immagini, ma per avere il lazy loading di immagini &lt;em&gt;responsive&lt;/em&gt; avrai bisogno di quella che ho scritto io: &lt;a href=&quot;http://verlok.github.io/vanilla-lazyload/&quot;&gt;LazyLoad&lt;/a&gt; (leggi tutti i suoi vantaggi &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/a-new-lazyload-to-improve-your-website-performance&quot;&gt;qui&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Inoltre, poiché non tutti i browser supportano le immagini responsive, dobbiamo includere la libreria &lt;a href=&quot;https://github.com/scottjehl/picturefill&quot;&gt;picturefill&lt;/a&gt; di Filament Group, un polyfill che ci permette di colmare questa lacuna e far funzionare le immagini responsive su tutti i browser. Nota che questa libreria non sarà più necessaria quando tutti i browser che devi supportare offriranno il supporto nativo alle immagini responsive.&lt;/p&gt;
&lt;p&gt;Quindi includeremo questi 2 script:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;js/vendor/lazyload.min.js&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;js/vendor/picturefill.min.js&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;inizializzazione-dello-script&quot; tabindex=&quot;-1&quot;&gt;Inizializzazione dello script &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/#inizializzazione-dello-script&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Quello che dobbiamo fare è creare una nuova istanza di &lt;code&gt;LazyLoad&lt;/code&gt; per trasformare l&#39;attributo &lt;code&gt;data-srcset&lt;/code&gt; in un vero e proprio attributo &lt;code&gt;srcset&lt;/code&gt;. Questo sarebbe sufficiente per i browser che supportano nativamente le &lt;em&gt;immagini responsive&lt;/em&gt; ma, per gli altri, dobbiamo chiamare &lt;code&gt;picturefill&lt;/code&gt; subito dopo che &lt;code&gt;LazyLoad&lt;/code&gt; ha modificato il DOM.&lt;/p&gt;
&lt;p&gt;Possiamo fare tutto ciò con questo comando:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/*var myLazyLoad = */&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LazyLoad&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;data_src&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;src&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;data_srcset&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;srcset&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;show_while_loading&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// ideale per JPEG progressivi&lt;/span&gt;
	&lt;span class=&quot;token function-variable function&quot;&gt;callback_set&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;img&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token function&quot;&gt;picturefill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token literal-property property&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;img&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Per ulteriori riferimenti su ciò che abbiamo fatto qui, consulta la &lt;a href=&quot;http://verlok.github.io/vanilla-lazyload/&quot;&gt;documentazione di LazyLoad&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;il-foglio-di-stile&quot; tabindex=&quot;-1&quot;&gt;Il foglio di stile &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/#il-foglio-di-stile&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Ci sono anche alcune funzionalità che possono essere ottenute solo tramite CSS. Dobbiamo:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Fare in modo che le immagini vuote occupino un certo spazio. Se non lo facciamo, tutte le immagini vuote collasseranno una sull&#39;altra ed entreranno nella viewport contemporaneamente, vanificando i nostri sforzi di caricarle in modo lazy.&lt;/li&gt;
&lt;li&gt;Evitare che le immagini vuote appaiano come immagini non trovate (broken)&lt;/li&gt;
&lt;li&gt;(se abbiamo usato l&#39;opzione &lt;code&gt;show_while_loading&lt;/code&gt;, come nel nostro caso) Risolvere un&#39;anomalia di Firefox che mostra l&#39;icona dell&#39;immagine interrotta durante il caricamento delle immagini&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Possiamo fare tutto questo usando queste regole CSS:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/*
Fa in modo che il contenitore delle immagini occupi spazio
quando le immagini non sono ancora caricate.
Questo valore dipende dal tuo layout.
*/&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.imageList li&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;min-height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 300px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;/*
Evita che le immagini vuote appaiano come interrotte (broken)
*/&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;img:not([src]):not([srcset])&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;visibility&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;/*
Risolve l&#39;anomalia di Firefox durante il caricamento delle immagini
*/&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@-moz-document&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;url-prefix&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;img:-moz-loading&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token property&quot;&gt;visibility&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;tutto-qui&quot; tabindex=&quot;-1&quot;&gt;Tutto qui! &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/lazy-load-responsive-images-srcset/#tutto-qui&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;È stato molto facile, vero? Se non l&#39;hai ancora fatto, &lt;a href=&quot;http://verlok.github.io/img_srcset_lazyload&quot;&gt;dai un&#39;occhiata alla demo&lt;/a&gt; di ciò che abbiamo realizzato.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Generazione avanzata di sprite con Compass (SASS)</title>
		<link href="https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/"/>
		<updated>2015-03-06T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/</id>
		<content type="html">&lt;p&gt;La creazione di sprite (spriting) è un modo per migliorare le prestazioni del tuo sito web posizionando molte immagini (o icone) all&#39;interno di un&#39;unica immagine più grande, in modo da effettuare una sola richiesta HTTP anziché molte. Ecco come puoi creare gli sprite utilizzando Compass.&lt;/p&gt;
&lt;h2 id=&quot;il-metodo-semplice&quot; tabindex=&quot;-1&quot;&gt;Il metodo semplice &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#il-metodo-semplice&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il modo più semplice per creare uno sprite con Compass richiede di importare una cartella di immagini nel progetto e poi generare una classe per ciascuno sprite. Puoi farlo utilizzando il seguente codice:&lt;/p&gt;
&lt;pre class=&quot;language-scss&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Importazione dello strumento Compass richiesto&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;compass/utilities/sprites&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// Importazione di tutte le immagini png all&#39;interno della cartella flags&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;flags/*.png&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// Genera una classe CSS per ogni sprite&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@include&lt;/span&gt; all-flags-sprites&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Esempio di output CSS:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.flags-it,
.flags-de,
.flags-fr&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string url&quot;&gt;&#39;/images/flags-s34fe0604ab.png&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; no-repeat&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.flags-it&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;background-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.flags-de&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;background-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 -32px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.flags-fr&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;background-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 -64px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Questo potrebbe essere sufficiente per le tue esigenze... ma tu vuoi di più, vero?&lt;/p&gt;
&lt;h2 id=&quot;il-metodo-avanzato&quot; tabindex=&quot;-1&quot;&gt;Il metodo avanzato &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#il-metodo-avanzato&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Tralasciando tutti gli altri modi in cui è possibile generare gli sprite con Compass, ho scoperto che se devi fare quanto segue:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Generare dimensioni del box uguali a quelle dello sprite&lt;/li&gt;
&lt;li&gt;Usare un offset all&#39;interno del box&lt;/li&gt;
&lt;li&gt;Spaziare gli sprite all&#39;interno della mappa degli sprite (sprite map)&lt;/li&gt;
&lt;li&gt;Gestire display con densità 1x, 2x, 3x&lt;/li&gt;
&lt;li&gt;Ottimizzare il tempo di generazione degli sprite&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;L&#39;unico modo per fare spriting con Compass è creare i tuoi mixin personali che utilizzino sotto il cofano i mixin di base di Compass.&lt;/p&gt;
&lt;h3 id=&quot;struttura-delle-immagini-e-delle-cartelle&quot; tabindex=&quot;-1&quot;&gt;Struttura delle immagini e delle cartelle &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#struttura-delle-immagini-e-delle-cartelle&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Per avere le immagini a densità singola, doppia e magari tripla, dobbiamo fornire le immagini in dimensioni 1x, 2x e magari 3x.&lt;/p&gt;
&lt;p&gt;Quindi, supponendo di voler creare una mappa di sprite contenente delle &lt;strong&gt;bandiere (flags)&lt;/strong&gt;, puoi avere le seguenti cartelle nella cartella delle immagini:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;flagsSprite1x - &lt;em&gt;immagini delle bandiere a densità singola&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;flagsSprite2x - &lt;em&gt;immagini delle bandiere a densità doppia&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;flagsSprite3x - &lt;em&gt;...densità tripla&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;E se volessimo creare anche una mappa di sprite per delle &lt;strong&gt;icone (icons)&lt;/strong&gt;, dovremmo creare le cartelle:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;iconsSprite1x
&lt;ul&gt;
&lt;li&gt;...&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;iconsSprite2x
&lt;ul&gt;
&lt;li&gt;...&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;iconsSprite3x
&lt;ul&gt;
&lt;li&gt;...&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ora diamo un&#39;occhiata ai partial SASS da creare.&lt;/p&gt;
&lt;h3 id=&quot;partial-sass&quot; tabindex=&quot;-1&quot;&gt;Partial SASS &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#partial-sass&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Per garantire la massima flessibilità e il minor tempo di compilazione (build), ti suggerisco di utilizzare la seguente struttura:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;_variables.scss - tutte le tue variabili&lt;/li&gt;
&lt;li&gt;_mixins.scss - tutti i tuoi mixin&lt;/li&gt;
&lt;li&gt;un file partial per ogni set di immagini:
&lt;ul&gt;
&lt;li&gt;_flagsSprite.scss - bandiere&lt;/li&gt;
&lt;li&gt;_iconsSprite.scss - icone&lt;/li&gt;
&lt;li&gt;...&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Vediamo cosa inserire nei nostri partial, uno per uno.&lt;/p&gt;
&lt;h3 id=&quot;mixins-scss&quot; tabindex=&quot;-1&quot;&gt;_mixins.scss &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#mixins-scss&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Ecco alcuni mixin che potresti voler includere nel tuo file dei mixin. Trovi la spiegazione del loro funzionamento direttamente nei commenti del codice.&lt;/p&gt;
&lt;pre class=&quot;language-scss&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/*
Rende possibile l&#39;utilizzo di uno sprite a densità n-pla
Adatta automaticamente background-size e offset quando $multiplier è maggiore di 1
Consente di utilizzare la generazione automatica delle dimensioni, che viene adattata automaticamente quando $multiplier è maggiore di 1

Parametri richiesti:
- $sprite - il nome dello sprite
- $spriteMap - la variabile spriteMap
- $spriteUrl - l&#39;url della mappa degli sprite dello sprite

Parametri opzionali:
- $multiplier (1) - la densità dello sprite (1 per densità singola, 2 per retina, 3, ecc.)
- $renderSize (false) - indica al mixin di impostare width e height del box contenente lo sprite
- $offsetX (0) - l&#39;offset orizzontale (px) per l&#39;immagine nel box
- $offsetY (0) - l&#39;offset verticale (px) per l&#39;immagine nel box
*/&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@mixin&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useNxSprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$sprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$spriteMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$spriteUrl&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$multiplier&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$renderSize&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$offsetX&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$offsetY&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$spritePosition&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sprite-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$spriteMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$offsetX&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$multiplier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$offsetY&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$multiplier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transparent &lt;span class=&quot;token variable&quot;&gt;$spriteUrl&lt;/span&gt; no-repeat &lt;span class=&quot;token function&quot;&gt;nth&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$spritePosition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$multiplier&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;nth&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$spritePosition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$multiplier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;@if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$multiplier&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;background-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;image-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sprite-path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$spriteMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$multiplier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;image-height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sprite-path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$spriteMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$multiplier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;@if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$renderSize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;image-height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sprite-file&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$spriteMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$multiplier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;image-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sprite-file&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$spriteMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$multiplier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/*
Mixin di utilità per utilizzare sprite a singola e doppia densità, con media query per la doppia densità inclusa

Parametri richiesti:
- $sprite - il nome dello sprite
- $sprite1xMap - la variabile spriteMap per gli sprite 1x
- $sprite2xMap - la variabile spriteMap per gli sprite 2x
- $sprite1xUrl - l&#39;url della mappa degli sprite per gli sprite 1x
- $sprite2xUrl - l&#39;url della mappa degli sprite per gli sprite 2x

Parametri opzionali:
- $renderSize (false) - indica al mixin di impostare width e height del box contenente lo sprite
- $offsetX (0) - l&#39;offset orizzontale (px) per l&#39;immagine nel box
- $offsetY (0) - l&#39;offset verticale (px) per l&#39;immagine nel box
*/&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@mixin&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;use1x2xSprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$sprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite1xMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite2xMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite1xUrl&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite2xUrl&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$renderSize&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$offsetX&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$offsetY&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;@include&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useNxSprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$sprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite1xMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite1xUrl&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$renderSize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$offsetX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$offsetY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;-webkit-min-device-pixel-ratio&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-resolution&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 144dpi&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;@include&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useNxSprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$sprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite2xMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$sprite2xUrl&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 2&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$renderSize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$offsetX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$offsetY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;variables-scss&quot; tabindex=&quot;-1&quot;&gt;_variables.scss &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#variables-scss&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Questo è il file in cui definisci tutte le variabili del tuo sito, che utilizzerai in tutti i tuoi file scss.&lt;/p&gt;
&lt;p&gt;Qui dovresti definire la spaziatura tra gli sprite nelle immagini della mappa degli sprite.&lt;/p&gt;
&lt;pre class=&quot;language-scss&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Spaziatura generica (a 1x) per gli sprite&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$spacing-sprites-generic&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;flagssprite-scss&quot; tabindex=&quot;-1&quot;&gt;_flagsSprite.scss &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#flagssprite-scss&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Questo è il file in cui definisci le variabili e i mixin per gli sprite delle bandiere.&lt;/p&gt;
&lt;p&gt;Ti suggerisco di importare (&lt;code&gt;@import&lt;/code&gt;) il file &lt;code&gt;_flagsSprite.scss&lt;/code&gt; solo nei file che richiedono effettivamente gli sprite delle bandiere. Questo &lt;strong&gt;velocizza molto il tempo di build&lt;/strong&gt;, evitando frequenti controlli delle immagini sul file system.&lt;/p&gt;
&lt;pre class=&quot;language-scss&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// MAPPE e URL per flagsSprite&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$flagsSprite1xMap&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sprite-map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;flagsSprite1x/*.png&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$spacing&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$spacing-sprites-generic&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$flagsSprite2xMap&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sprite-map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;flagsSprite2x/*.png&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$spacing&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$spacing-sprites-generic&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; 2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$flagsSprite1xUrl&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token url&quot;&gt;sprite-url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$flagsSprite1xMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$flagsSprite2xUrl&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token url&quot;&gt;sprite-url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$flagsSprite2xMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// mixin flagsSprite&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@mixin&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;flagsSprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$spriteName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$renderSize&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$offsetX&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$offsetY&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;@include&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;use1x2xSprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$spriteName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$flagsSprite1xMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$flagsSprite2xMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$flagsSprite1xUrl&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$flagsSprite2xUrl&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$renderSize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$offsetX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$offsetY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;style-scss-uso-standard&quot; tabindex=&quot;-1&quot;&gt;style.scss - uso standard &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#style-scss-uso-standard&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Se non hai bisogno di spazio attorno allo sprite e non vuoi che Compass generi le dimensioni del box per te, puoi semplicemente fare così.&lt;/p&gt;
&lt;pre class=&quot;language-scss&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;compass/utilities/sprites&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;_variables&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;_flagsSprite&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Uso semplice&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.exampleSimple &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;@include&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;flagsSprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;italy&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Questo produrrà quanto segue:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.exampleSimple&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transparent &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string url&quot;&gt;&#39;../img/flagsSprite1x-s479625030c.png&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; no-repeat 0 -882px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;-webkit-min-device-pixel-ratio&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-resolution&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 144dpi&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;.exampleSimple&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transparent &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string url&quot;&gt;&#39;../img/flagsSprite2x-s9a855cf705.png&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; no-repeat 0 -882px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;background-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 32px 2048px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;style-scss-con-generazione-delle-dimensioni-del-box&quot; tabindex=&quot;-1&quot;&gt;style.scss - con generazione delle dimensioni del box &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#style-scss-con-generazione-delle-dimensioni-del-box&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Se vuoi che Compass generi le dimensioni del box per te, devi fare come segue.&lt;/p&gt;
&lt;pre class=&quot;language-scss&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;compass/utilities/sprites&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;_variables&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;_flagsSprite&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.exampleWithDimensions &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;@include&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;flagsSprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;italy&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Questo produrrà quanto segue:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.exampleWithDimensions&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transparent &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string url&quot;&gt;&#39;../img/flagsSprite1x-s479625030c.png&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; no-repeat 0 -882px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 32px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 32px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;-webkit-min-device-pixel-ratio&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-resolution&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 144dpi&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;.exampleWithDimensions&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transparent &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string url&quot;&gt;&#39;../img/flagsSprite2x-s9a855cf705.png&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; no-repeat 0 -882px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;background-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 32px 2048px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 32px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 32px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;style-scss-con-gestione-dell-offset&quot; tabindex=&quot;-1&quot;&gt;style.scss - con gestione dell&#39;offset &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#style-scss-con-gestione-dell-offset&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Se non vuoi che Compass generi le dimensioni del box per te, ma desideri utilizzare un offset all&#39;interno del box, devi fare come segue.&lt;/p&gt;
&lt;pre class=&quot;language-scss&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;compass/utilities/sprites&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;_variables&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;_flagsSprite&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.exampleWithPadding &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;@include&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;flagsSprite&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;italy&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 10&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 10&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 52px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 52px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Questo produrrà quanto segue:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.exampleWithPadding&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transparent &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string url&quot;&gt;&#39;../img/flagsSprite1x-s479625030c.png&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; no-repeat 10px -872px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 52px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 52px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;-webkit-min-device-pixel-ratio&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;min-resolution&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 144dpi&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;.exampleWithPadding&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transparent &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string url&quot;&gt;&#39;../img/flagsSprite2x-s9a855cf705.png&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; no-repeat 10px -872px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;background-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 32px 2048px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;tutto-qui&quot; tabindex=&quot;-1&quot;&gt;Tutto qui &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/advanced-sprite-generation-using-compass-sass/#tutto-qui&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;La generazione automatica di sprite tramite Compass considerando tutti i fattori può essere piuttosto complessa, ma seguendo questa guida sarà semplice e anche più facile da mantenere.&lt;/p&gt;
&lt;p&gt;Se hai riscontrato problemi con questo post, per favore &lt;a href=&quot;https://twitter.com/verlok&quot;&gt;mandami un tweet&lt;/a&gt; e provvederò a risolverli.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Un nuovo LazyLoad per migliorare le prestazioni del tuo sito web</title>
		<link href="https://andreaverlicchi.eu/it/blog/a-new-lazyload-to-improve-your-website-performance/"/>
		<updated>2014-11-20T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/a-new-lazyload-to-improve-your-website-performance/</id>
		<content type="html">&lt;p&gt;Negli ultimi giorni ho lavorato all&#39;ottimizzazione delle prestazioni dei siti web e mi sono reso conto che non c&#39;è modo di sfruttare il formato di immagine &lt;strong&gt;JPEG progressivo&lt;/strong&gt; sui siti web se si utilizza &lt;a href=&quot;https://github.com/tuupola/jquery_lazyload&quot; title=&quot;Mika Tuupola&quot;&gt;jQuery_lazyload&lt;/a&gt;. Quindi, dopo aver inviato una pull request al suo autore, ho deciso di scrivere il mio lazy load personale, che si è rivelato migliore perché:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;è 6 volte più veloce&lt;/li&gt;
&lt;li&gt;consente di &lt;a href=&quot;https://andreaverlicchi.eu/it/blog/a-new-lazyload-to-improve-your-website-performance/lazy-load-responsive-images-srcset&quot;&gt;caricare in modalità lazy le immagini responsive&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;non dipende da jQuery&lt;/li&gt;
&lt;li&gt;supporta al meglio il formato JPEG progressivo&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Maggiori informazioni sul &lt;a href=&quot;https://github.com/verlok/vanilla-lazyload&quot;&gt;repository GitHub&lt;/a&gt;.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Animazione di caricamento &quot;loading&quot; rotante in solo CSS 3</title>
		<link href="https://andreaverlicchi.eu/it/blog/css-3-only-spinning-loading-animation/"/>
		<updated>2012-10-03T00:00:00Z</updated>
		<id>https://andreaverlicchi.eu/it/blog/css-3-only-spinning-loading-animation/</id>
		<content type="html">&lt;p&gt;Abbiamo usato immagini GIF per creare animazioni per anni, ma non sono adatte ad essere utilizzate sopra sfumature o immagini (niente canale alfa, niente anti-aliasing) di cui i siti web moderni sono pieni. Esistono molte soluzioni alternative per animare invece immagini PNG, ma...&lt;/p&gt;
&lt;p&gt;Voglio mostrarti una soluzione che ho trovato per creare un&#39;animazione di caricamento (&amp;quot;loading&amp;quot;) da zero, utilizzando solo CSS 3, senza immagini.&lt;/p&gt;
&lt;h2 id=&quot;prima-i-risultati&quot; tabindex=&quot;-1&quot;&gt;Prima i risultati &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/css-3-only-spinning-loading-animation/#prima-i-risultati&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p data-height=&quot;265&quot; data-theme-id=&quot;0&quot; data-slug-hash=&quot;bWmvON&quot; data-default-tab=&quot;css,result&quot; data-user=&quot;verlok&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;CSS 3 only spinning circle quarter - loading animation&quot; class=&quot;codepen&quot;&gt;Vedi la Pen &lt;a href=&quot;https://codepen.io/verlok/pen/bWmvON/&quot;&gt;CSS 3 only spinning circle quarter - loading animation&lt;/a&gt; di Andrea Verlicchi (&lt;a href=&quot;https://codepen.io&quot;&gt;@verlok&lt;/a&gt;) su &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;script async=&quot;&quot; src=&quot;https://production-assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
&lt;h2 id=&quot;cosa-succede-qui&quot; tabindex=&quot;-1&quot;&gt;Cosa succede qui &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/css-3-only-spinning-loading-animation/#cosa-succede-qui&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Il fulcro di questo metodo consiste nel disegnare un quarto di cerchio e animarlo.
Continua a leggere per scoprire i passaggi passo-passo per farlo.&lt;/p&gt;
&lt;h2 id=&quot;1-creare-un-cerchio&quot; tabindex=&quot;-1&quot;&gt;1. Creare un cerchio &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/css-3-only-spinning-loading-animation/#1-creare-un-cerchio&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Cerchio interno mascherato --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;maskedCircle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* Cerchio rotante (cerchio interno) */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.loading .maskedCircle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3px solid white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;2-mascherare-un-quarto-del-cerchio&quot; tabindex=&quot;-1&quot;&gt;2. Mascherare un quarto del cerchio &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/css-3-only-spinning-loading-animation/#2-mascherare-un-quarto-del-cerchio&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Maschera del quarto di cerchio --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;mask&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Cerchio interno mascherato --&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;maskedCircle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* Maschera del cerchio rotante */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.loading .mask&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;overflow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;3-far-ruotare-entrambi&quot; tabindex=&quot;-1&quot;&gt;3. Far ruotare entrambi &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/css-3-only-spinning-loading-animation/#3-far-ruotare-entrambi&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Facciamo ruotare questo div --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;spinner&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Maschera del quarto di cerchio --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;mask&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Cerchio interno mascherato --&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;maskedCircle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* Keyframe dell&#39;animazione */&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; spin&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;360deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* Spinner */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.loading .spinner&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 26px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 26px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; spin 1s infinite linear&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;4-avvolgere-tutto-in-un-contenitore-loading-che-sara-centrato-rispetto-al-suo-genitore&quot; tabindex=&quot;-1&quot;&gt;4. Avvolgere tutto in un contenitore &amp;quot;loading&amp;quot;, che sarà centrato rispetto al suo genitore &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/css-3-only-spinning-loading-animation/#4-avvolgere-tutto-in-un-contenitore-loading-che-sara-centrato-rispetto-al-suo-genitore&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Contenitore dell&#39;animazione di caricamento --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;loading&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Facciamo ruotare questo div --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;spinner&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Maschera del quarto di cerchio --&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;mask&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Cerchio interno mascherato --&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;maskedCircle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* Contenitore dell&#39;animazione di caricamento */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.loading&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 28px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 28px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -14px 0 0 -14px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;codice-html-e-css-risultante&quot; tabindex=&quot;-1&quot;&gt;Codice HTML e CSS risultante: &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/css-3-only-spinning-loading-animation/#codice-html-e-css-risultante&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-html&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Contenitore dell&#39;animazione di caricamento --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;loading&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Facciamo ruotare questo div --&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;spinner&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Maschera del quarto di cerchio --&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;mask&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Cerchio interno mascherato --&gt;&lt;/span&gt;
			&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;maskedCircle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
	&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* Keyframe dell&#39;animazione - devi aggiungere i prefissi */&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; spin&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token selector&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;360deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* Contenitore dell&#39;animazione di caricamento */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.loading&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 28px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 28px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -14px 0 0 -14px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* Cerchio rotante (cerchio interno) */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.loading .maskedCircle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3px solid white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* Maschera del cerchio rotante */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.loading .mask&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;overflow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* Spinner */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.loading .spinner&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 26px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 26px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; spin 1s infinite linear&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Non è fantastico?&lt;/p&gt;
&lt;p&gt;Funziona perfettamente su tutti i browser desktop come:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Internet Explorer 10+&lt;/li&gt;
&lt;li&gt;Edge&lt;/li&gt;
&lt;li&gt;Chrome&lt;/li&gt;
&lt;li&gt;Firefox&lt;/li&gt;
&lt;li&gt;Safari&lt;/li&gt;
&lt;li&gt;Opera&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;e anche per tutti i principali browser mobile:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Safari Mobile&lt;/li&gt;
&lt;li&gt;Chrome Mobile&lt;/li&gt;
&lt;li&gt;Firefox Mobile&lt;/li&gt;
&lt;li&gt;Opera Mobile&lt;/li&gt;
&lt;li&gt;Internet Explorer Mobile (solo Windows Phone 8)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Al momento, Internet Explorer su Windows Phone 7 non animerà la figura.&lt;/p&gt;
&lt;h2 id=&quot;i-fallback&quot; tabindex=&quot;-1&quot;&gt;I fallback? &lt;a class=&quot;header-anchor&quot; href=&quot;https://andreaverlicchi.eu/it/blog/css-3-only-spinning-loading-animation/#i-fallback&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Hai bisogno di un fallback per vedere l&#39;animazione nei browser più vecchi? Se hai letto fin qui, probabilmente sì.&lt;/p&gt;
&lt;p&gt;Sebbene il fallback non sia lo scopo di questo articolo, diciamo che la soluzione migliore sarebbe preparare &lt;strong&gt;uno sprite con tutti i fotogrammi (frame)&lt;/strong&gt; dell&#39;animazione a una distanza costante l&#39;uno dall&#39;altro, usare lo sprite come sfondo di un elemento DOM e &lt;strong&gt;animare lo sfondo con Javascript&lt;/strong&gt;.&lt;/p&gt;
</content>
	</entry>
</feed>
