Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

How to Stop Browser from Caching Stale Copy of JavaScript or CSS File

Автор: Johnny Code

Загружено: 2023-01-05

Просмотров: 2881

Описание:

This is a problem that every new web developer will run into. You modified your JavaScript file but the changes don't show up on the browser. So you hit F5 a bunch of times, double-checked that you really saved the file, and still nothing. Looks like your browser randomly decided to use the cached version of your JavaScript file.

Browsers cache resources, such as JavaScript, CSS, and images, to speed up subsequent page loads for users. However, sometimes the browser serves stale resources to the user, even though the resources have changed on the web server. This may happen if the target page, "index.php", for example, did not change, but its external JavaScript resource "myjavascript.js" did. The browser may (unpredictably) assume that if "index.php" is the same as the cached version, its linked resources should be the same.

We, developers, want our users or customers to utilize our latest updates. This caching issue is hard to reproduce because each browser's caching scheme is different and the implementation is a black box to us. There are no explicit built-in mechanisms to handle this exact issue. However, the workarounds are pretty simple.

Option 1. Disable caching for yourself so that this issue does not affect you while you code. In Chrome, for example, caching could be turned off in Chrome's built-in "Developer Tools", under the Network tab. When it is time to release to your production site, add a version number to your JavaScript file i.e. "myjavascript1.2.js". This ensures that browsers see the file as new. The problem with this approach is the hassle of applying and managing the version number.

Option 2. In PHP, as well as any other server-side language, this could be accomplished by adding the file's last modified timestamp to the src attribute. Youtube does not allow sample code here, but you the code from here: https://theavg.dev/web-dev-gotchas-ja...

How to Stop Browser from Caching Stale Copy of JavaScript or CSS File

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

array(10) { [0]=> object(stdClass)#4153 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "1igp5xJni7M" ["related_video_title"]=> string(52) "How to Capture Browser Redirects in Chrome Dev Tools" ["posted_time"]=> string(21) "2 года назад" ["channelName"]=> string(11) "Johnny Code" } [1]=> object(stdClass)#4126 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "hOtZhNb4TKg" ["related_video_title"]=> string(36) "JavaScript Security: Hide your Code?" ["posted_time"]=> string(19) "6 лет назад" ["channelName"]=> string(9) "Academind" } [2]=> object(stdClass)#4151 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "mSMb-aH6sUw" ["related_video_title"]=> string(69) "Caching demystified: Inspect, clear, and disable caches #DevToolsTips" ["posted_time"]=> string(27) "9 месяцев назад" ["channelName"]=> string(21) "Chrome for Developers" } [3]=> object(stdClass)#4158 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "Cy2ZJOBgk84" ["related_video_title"]=> string(86) "Deep Dive into HTTP Caching: cache-control, no-cache, no-store, max-age, ETag and etc." ["posted_time"]=> string(21) "2 года назад" ["channelName"]=> string(26) "Software Developer Diaries" } [4]=> object(stdClass)#4137 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "3ncFpP8GP4g" ["related_video_title"]=> string(60) "The new CSS pseudo-classes explained - :is() :where() :has()" ["posted_time"]=> string(21) "2 года назад" ["channelName"]=> string(12) "Kevin Powell" } [5]=> object(stdClass)#4155 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "zDlg64fsQow" ["related_video_title"]=> string(150) "Event Loop от А до Я. Архитектура браузера и Node JS. Движки и рендер. Самое подробное видео" ["posted_time"]=> string(21) "2 года назад" ["channelName"]=> string(7) "Ulbi TV" } [6]=> object(stdClass)#4150 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "nec3aZM8aUY" ["related_video_title"]=> string(83) "Deep House Mix 2024 | Deep House, Vocal House, Nu Disco, Chillout Mix by Diamond #3" ["posted_time"]=> string(19) "1 год назад" ["channelName"]=> string(7) "Diamond" } [7]=> object(stdClass)#4160 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "RnHC1XiNWS8" ["related_video_title"]=> string(94) "Венедиктов – страх, Симоньян, компромиссы / вДудь" ["posted_time"]=> string(21) "6 дней назад" ["channelName"]=> string(10) "вДудь" } [8]=> object(stdClass)#4136 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "IcLWETIf3J4" ["related_video_title"]=> string(116) "Жириновский о евреях! Что будет, когда Израиль проиграет? 2004 год" ["posted_time"]=> string(19) "1 год назад" ["channelName"]=> string(13) "ЛДПР-ТВ" } [9]=> object(stdClass)#4154 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "qHh_B97OjEY" ["related_video_title"]=> string(97) "SOLID принципы в 2025: Полный разбор и прожарка / @S0ERDEVS / #12" ["posted_time"]=> string(27) "8 месяцев назад" ["channelName"]=> string(93) "Организованное программирование | Кирилл Мокевнин" } }
How to Capture Browser Redirects in Chrome Dev Tools

How to Capture Browser Redirects in Chrome Dev Tools

JavaScript Security: Hide your Code?

JavaScript Security: Hide your Code?

Caching demystified: Inspect, clear, and disable caches #DevToolsTips

Caching demystified: Inspect, clear, and disable caches #DevToolsTips

Deep Dive into HTTP Caching: cache-control, no-cache, no-store, max-age, ETag and etc.

Deep Dive into HTTP Caching: cache-control, no-cache, no-store, max-age, ETag and etc.

The new CSS pseudo-classes explained - :is() :where() :has()

The new CSS pseudo-classes explained - :is() :where() :has()

Event Loop от А до Я. Архитектура браузера и Node JS. Движки и рендер. Самое подробное видео

Event Loop от А до Я. Архитектура браузера и Node JS. Движки и рендер. Самое подробное видео

Deep House Mix 2024 | Deep House, Vocal House, Nu Disco, Chillout Mix by Diamond #3

Deep House Mix 2024 | Deep House, Vocal House, Nu Disco, Chillout Mix by Diamond #3

Венедиктов – страх, Симоньян, компромиссы / вДудь

Венедиктов – страх, Симоньян, компромиссы / вДудь

Жириновский о евреях! Что будет, когда Израиль проиграет? 2004 год

Жириновский о евреях! Что будет, когда Израиль проиграет? 2004 год

SOLID принципы в 2025: Полный разбор и прожарка /  @S0ERDEVS  / #12

SOLID принципы в 2025: Полный разбор и прожарка / @S0ERDEVS / #12

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]