Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 248|回复: 0

This results in less code cluttering the

[复制链接]

6

主题

6

帖子

20

积分

新手上路

积分
20
发表于 2024-2-14 18:45:35 | 显示全部楼层 |阅读模式
Doing this can speed up page load time, significantly help rankings and save crawl budget. Benefits of Externalizing CSS Creating an external CSS file gives you one place to control the look of the website, so it’s much more efficient than editing every single page of a website when you want to make a change. When you have a CSS file, you only need to make changes to the external file and those changes are applied to the entire site. Having an external CSS file has other benefits, too. It allows you to remove inline formatting, such as font tags, and replace them with CSS tags that instruct what style to apply.  webpage. Less code means smaller file sizes. Smaller file sizes mean web pages load faster. Benefits of Externalizing JavaScript Creating an external file for JavaScript has similar benefits.




When you move the JavaScript off individual webpages and into an external file, your webpages only need a single line of code that calls the JavaScript file for information. JavaScript tends to be long and cumbersome, so doing this one simple thing Belgium Email List could cut the size of a webpage in half. Is Your JavaScript and CSS Externalized Already? It’s easy to check if your CSS and JavaScript is externalized. Go to your website homepage and look at the source code. To vieup the page load time and performance, for instance, in cases where JavaScript blocks the rendering of the page. Using in-line JavaScript at the top of the page may enable content at the top of the page to become visible to users without having to wait for large JavaScript files to load. So, here’s how to externalize JavaScript: Identify the JavaScript code that you want to externalize by locating the opening and closing <script> tag with the HTML source code of the webpage. Cut the javascript code, which is between <script> and </script>. Using a text editor like Notepad, create a new document and paste the JS code into the new blank document. Save the file with the file extension “.js”. Upload the file to your server and make a note of its path.







Go back to your original html file and insert the following, where “path/filesource.js” is the URL of the newly created .js file: <script language=”JavaScript” src=”path/filesource.js”></script> Now, the embedded JavaScript code is replaced with just one line. When search engines crawl the webpage, they will only have one line of code to read before they go on to the rest of the page. Subsequently, this can help with Google’s page experience algorithm update, specifically, First Input Delay. (Note that FID will be replaced by Interaction to Next Paint (INP) in March 2024.) How to Externalize CSS To externalize style sheets, simply follow the same instructions as for the JavaScript file, except save the file with a .css file extension. In the original webpage code you’ll replace all the CSS coding with the following: <link href=”cssfilename” rel=”stylesheet” type=”text/css”> Once again you are left with one line of code on your original page, allowing for simpler site indexing for the spiders. Small Steps, Big Impact Externalizing JavaScript and CSS won’t fix your website performance problems, but it’s a great start. One client we worked with implemented these two best practices and reduced 20,000 lines of code to 1,500.

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Discuz! X

GMT+8, 2024-9-22 01:15 , Processed in 0.031250 second(s), 19 queries .

Powered by Discuz! X3.5

Copyright © 2001-2022 Tencent Cloud.

快速回复 返回顶部 返回列表