{"id":232675,"date":"2023-01-26T12:41:00","date_gmt":"2023-01-26T09:41:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232675"},"modified":"2023-01-26T12:41:48","modified_gmt":"2023-01-26T09:41:48","slug":"come-dire-ai-browser-di-aggiornare-nuovamente-i-file-css-js-quando-i-file-vengono-modificati-in-wordpress","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/it\/come-dire-ai-browser-di-aggiornare-nuovamente-i-file-css-js-quando-i-file-vengono-modificati-in-wordpress\/","title":{"rendered":"Come dire ai browser di aggiornare nuovamente i file CSS\/JS quando i file vengono modificati in WordPress?"},"content":{"rendered":"<p>Nelle intestazioni di <a href=\"https:\/\/wordpress.mediadoma.com\/it\/script-php-per-proteggere-le-cartelle-di-wordpress-impostando-le-autorizzazioni-file-corrette\/\" title=\"wordpress\">wordpress<\/a>, probabilmente noterai che le risorse statiche <a href=\"https:\/\/helloacm.com\/css-for-image-onmouseover-event\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">CSS<\/a> e <a href=\"https:\/\/helloacm.com\/tutorial-example-how-to-access-microsoft-excel-chart-using-the-windows-scripting-host-jscript\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">JS sono referenziate in questo modo:<\/a><\/p>\n<pre><code>https:\/\/justyy.com\/wp-content\/themes\/twentytwelve\/style.css?ver=4.4.2<\/code><\/pre>\n<p>La stringa di query <strong>?ver=<\/strong> viene utilizzata per dire ai browser di eseguire un aggiornamento forzato sulle risorse statiche quando la versione core di wordpress \u00e8 cambiata perch\u00e9 alcuni browser potrebbero non essere in grado di ignorare i file di cache poich\u00e9 l&#8217;URL non \u00e8 cambiato.<\/p>\n<p>A volte, voglio cambiare <strong>style.css<\/strong> nel <a href=\"https:\/\/helloacm.com\/schema-2-0-dont-let-google-penalize-your-slow-loading-website\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">tema figlio<\/a> ma il browser sta ancora recuperando il file memorizzato nella cache poich\u00e9 la versione di wordpress non \u00e8 cambiata. e devo andare su <a href=\"https:\/\/helloacm.com\/cloudflare-weaker-sha1-ssl-to-support-all-browsers\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">CloudFlare<\/a> per svuotare la cache. Una soluzione migliore \u00e8 cambiare <strong>?ver=<\/strong> in <strong>?filetime=<\/strong> in modo che ogni volta che il file \u00e8 stato modificato, l&#8217;URL cambia.<\/p>\n<p>Puoi aggiungere quanto segue nel template child-theme functions.php per fare in modo che ci\u00f2 accada.<\/p>\n<pre><code>function justyy_remove_cssjs_ver( $src) {\n\u00a0 $newsrc = $src;\n\u00a0 if( strpos( $newsrc, '?ver=')) {\n\u00a0 \u00a0 $newsrc = remove_query_arg( 'ver', $newsrc );\n\u00a0 }\n\u00a0 $rootdir = '\/var\/www'; \/\/ the path to your domain on the server\n\u00a0 $url = parse_url($newsrc, PHP_URL_PATH);\n\u00a0 $source = $rootdir .'\/'. $url;\n\u00a0 if (is_file($source)) {\n\u00a0 \u00a0 $newsrc .= \"?m=\".filemtime($source);\n\u00a0 \u00a0 return $newsrc;\n\u00a0 } \u00a0 \u00a0 \n\u00a0 return $src; \/\/ keep unchanged if file is not accessible.\n}\nadd_filter( 'style_loader_src', 'justyy_remove_cssjs_ver', 10, 2 );\nadd_filter( 'script_loader_src', 'justyy_remove_cssjs_ver', 10, 2 );<\/code><\/pre>\n<p>Potresti usare <a href=\"https:\/\/helloacm.com\/file_put_contents-substitute-in-php\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">il contenuto del file<\/a>.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Fonte di registrazione:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Come dire ai browser di aggiornare nuovamente i file CSS\/JS quando i file vengono modificati in WordPress?<\/p>\n","protected":false},"author":1,"featured_media":223973,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[918,896,835,804,720,844,1089,865],"tags":[1168],"class_list":["post-232675","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-altro","category-codice","category-guida-per-principianti","category-php-6","category-sviluppatore","category-tutorial","category-velocita-del-sito","category-wordpress-6","tag-affiai-it"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts\/232675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/comments?post=232675"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts\/232675\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/media\/223973"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/media?parent=232675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/categories?post=232675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/tags?post=232675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}