return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Is it okay to have 1 .js file for each html page? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it okay to have 1 .js file for each html page? - Stack Overflow

programmeradmin0浏览0评论

Can I write it like this? Won't I have issues in terms of how fast my website loads?

for index.html:

<html>

<body>
  <script src="index.js"></script>
</body>

</html>

for about.html:

<html>

<body>
  <script src="about.js"></script>
</body>

</html>

for contact.html:

<html>

<body>
  <script src="contact.js"></script>
</body>

</html>

I just want to clear things up. Thanks in advance!

Can I write it like this? Won't I have issues in terms of how fast my website loads?

for index.html:

<html>

<body>
  <script src="index.js"></script>
</body>

</html>

for about.html:

<html>

<body>
  <script src="about.js"></script>
</body>

</html>

for contact.html:

<html>

<body>
  <script src="contact.js"></script>
</body>

</html>

I just want to clear things up. Thanks in advance!

Share Improve this question edited Dec 22, 2018 at 5:43 Nick Parsons 51.1k6 gold badges57 silver badges77 bronze badges asked Dec 22, 2018 at 5:32 Griffon_KatoGriffon_Kato 311 silver badge3 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

You should extract out mon features among all the javascript code you run on different pages.

Imagine index.js has a function to create a list. And about.js has the same function. When it es to updating that function you will want to change it in one place. Not the five pages you have.

As for speed if every page has a link for list.js file, it will only need to be downloaded by the browser once. It's code will be cached and used in all the other pages requested.

Yes you can use it like this way, your website load faster. But if you include all the JS to all the files, it'll load slower because loading time is increased coz all the three files load for all the three pages.

Or a different approach.

Try to convert all the three file into only 1 (This way you'll reduce the repetitive function) Then include this file to each file. By storing the file to cache memory, file only download (load) once then it'll be used from the cache memory. This way your speed will be increased. Refer to the following link: https://www.html5rocks./en/tutorials/appcache/beginner/

Try to research as much as possible. You'll get your solutions.

Tick right (✓) if my answer is helpful for you.

The pages load separately so having a script in another page does not affect how fast the current one loads.

In my opinion, if you are very concerned about the speed it is more important to ensure that you are only loading the scripts that you need in the current page.

The right approach is to split your code into multiple functions as appropriate.

To address loading performance, use a minifier which will minify and bundle all your code (include JavaScript, CSS and HTML). You won't be able to outperform an actual minifier anyway.

Depending on the technology you are using, minification can be a step during your build/deployment procedure, or a plugin for your CMS which will minify and cache your files as they are being accessed.

发布评论

评论列表(0)

  1. 暂无评论