简体   繁体   English

如何通过使一行代码成为HTML代码来最小化?

[英]How Can I minimize the HTML code by making it one line of code?

So I have made a web page of HTML, Inline CSS and JS. 因此,我制作了一个HTML,内联CSS和JS网页。 Since this page will be produced through JS function 由于此页面将通过JS函数产生

 opened.document.write();

I would like to put all the web page code into one line that can be taken in one of the previously mention function instead of repeating the same function for every new line. 我想将所有网页代码放在一行中,可以在前面提到的功能之一中使用,而不是在每一行中重复相同的功能。 I can't affors doing this manually,because the page contains too many lines of code. 我不能手动执行此操作,因为该页面包含太多代码行。

Is there a fast and clean way to do this? 有没有一种快速清洁的方法来做到这一点?

Notice: I used SOME PROGRAM to replace all " with \\" by one click, so I hope there is away to replace all the(Enter)s with (Backspace) or something like that. 注意:我使用SOME PROGRAM一键式替换了所有的“ \\”,所以希望可以用(Backspace)或类似的东西替换所有的(Enter)。


Elaboration 细化

I want to produce the whole page when the user click on a button which will call a JS function which will produce a new page and write it using the previously mentioned function. 当用户单击一个按钮时,我想生成整个页面,该按钮将调用JS函数,该函数将生成一个新页面并使用前面提到的函数编写它。

Hmm, well the answer is "Yes", but it's slightly disturbing what you are doing. 嗯,答案是“是”,但这在干扰您的工作。

I don't know if you can replace special characters in Word, but in most text editors (Textpad, Notepad++) you can replace via a 'regex' so you can write "\\r\\n" to replace all instances of newlines with whatever you wish. 我不知道您是否可以替换Word中的特殊字符,但是在大多数文本编辑器(Textpad,Notepad ++)中,您可以通过“ regex”进行替换,因此您可以编写“ \\ r \\ n”以将换行符的所有实例替换为你希望。

I must say, though, that I wonder why you wish to write out the document like that. 不过,我必须说,我想知道为什么您要这样写文件。 Can you elaborate? 你能详细说明吗?

You could use an online text editor with regex , paste your code in and fix up some regex to replace \\r and \\n with a whitespace or no spaces. 您可以使用带有正则表达式在线文本编辑器 ,将代码粘贴到其中,并修复一些正则表达式,以用空格或不带空格替换\\ r和\\ n。 I don't know regex so you'll have to do it or ask for it yourself. 我不知道正则表达式,所以您必须自己做或要求它。

Changing your HTML pages to be generated by Javascript is a Very Bad Idea. 更改要由Javascript生成的HTML页面是一个非常糟糕的主意。 You're making your entire website virtually invisible to Search Engines, users with javascript off, and those using screen readers, and for what benefit? 您正在使整个网站几乎对搜索引擎,关闭javascript的用户以及使用屏幕阅读器的用户不可见,这有什么好处? Saving a couple of hundred bytes? 保存几百个字节? Set up your webserver with gzip compression and proper cache control and leave the source as is. 使用gzip压缩和适当的缓存控制来设置您的Web服务器,并保持源不变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM