PHP Write Web Project

Source: Internet
Author: User
Write a Web project, the page JS is separate to put out in a JS file is better, or directly written in the HTML page is better? What are the pros and cons?


Reply to discussion (solution)

It must be taken out alone. Good, wrong. Easy to find

Easy to develop by itself, multi-page reuse
Together, the number of connections to the server is 1 less, but this does not affect the small site, large sites can also be cached to eliminate this impact
So it's better to separate.

Separate JS file is better

Separate JS file better I use the TP framework, if there is an AJAX request, then the URL needs to have the project name. But if I change the project name, wouldn't that be to change the URL of each JS all over again? Is there any easy way? If I write in the HTML page can directly use the TP framework defined constants, such as __root__,__app__

It's got to be alone. Good, error-friendly find I use the TP framework, if there is an AJAX request, then the URL needs to have the project name. But if I change the project name, wouldn't that be to change the URL of each JS all over again? Is there any easy way? If I write in the HTML page can directly use the TP framework defined constants, such as __root__,__app__

Easy to develop by itself, multi-page reuse
Together, the number of connections to the server is 1 less, but this does not affect the small site, large sites can also be cached to eliminate this impact
So separate better I use the TP framework, if there is an AJAX request, then the URL needs to have the project name. But if I change the project name, wouldn't that be to change the URL of each JS all over again? Is there any easy way? If I write in the HTML page can directly use the TP framework defined constants, such as __root__,__app__

Take it out, easy to modify! Also convenient for other file calls!

Must be separated well, easy code reuse and clear Structure!

It's such a big person, you can do it by yourself.

It's like you've made a lot of friends, and some of you are always in touch, so you put it in a cell phone group.

Some may only contact one or two times, do not have to put in the group?

It's such a big person, you can do it by yourself.

It's like you've made a lot of friends, and some of you are always in touch, so you put it in a cell phone group.

Some may only contact one or two times, do not have to put in the group? Halo, I am now considering the path of the problem.

Halo, I am now considering the path of the problem.
JS files usually use the absolute path of the site

If you need to debug offline, use a relative path and make sure to reference it down
That is, the JS file in the reference file in this level or subordinate directory

It's better to be alone ....

Reference 10 Floor wanql0203 's reply: Halo, I am now thinking about the path of the problem.
JS files usually use the absolute path of the site

If you need to debug offline, use a relative path and make sure to reference it down
That is, the JS file in the reference file in this level or subordinate directory I use the TP framework, if there is an AJAX request, then the URL needs to have the project name. But if I change the project name, wouldn't that be to change the URL of each JS all over again? Is there any easy way? If I write in the HTML page can directly use the TP framework defined constants, such as __root__,__app__

Does the TP framework have special AJAX support?
You just follow him.

Does the TP framework have special AJAX support?
That's what you're saying. I'm using jquery 、、、

I don't think you know what you're asking.

If JS is used in many pages, it is better to put in the JS file, if only in a certain page to use, then directly write to the page

Public writing in the JS file, a single page to use is written on the current page.

I don't think you know what I'm asking. Ajax written in jquery, the path uses an absolute path, which is the need to bring the project name. If the project name changes later, not every Ajax path needs to be modified? I just want to ask if there is a way to simplify, without changing each path.
If I put JS in the HTML, then I do not need to consider the problem of the path, you can use TP constant __app__ to replace, do not involve the project name. Then I can change the name of the project without modifying the AJAX path name.
So I asked this question.

In any case, demand is always the first place!
Now that you have used the path in JS, and you are not willing to change to a relative path
Is it not necessary to discuss the built-in or the outreach?
Of course, you can also embed the standalone JS file as a sub-template into the main template

You can create a dedicated path to the JS file, which defines all the path variables, and other JS files using this file to define the path variable. Then this special storage path JS file before the other JS files can be introduced.
As defined Path.js
Inside the definition of var filepath= "* * *";
The filepath is then used as a path in other files.
When used, it is defined in the page:

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.